The web server knows that "dothis.pl" is a cgi script (in Perl) and not a normal file (html page, image, etc.) so it executes it. Whan a script its executed, it "prints out" the web page, filling in bits as it goes on. A script can do almost anything and make any type of page.
CGI applications can do things like access databases (say to retreive user information or product details) and make log files on the server. Perl is a common language for cgi scripts, and PHP is very funky. Look it up on the web.
You will have encountered cgi-based things whenever you have use search engines, forums, ecommerce and just about everything else on the web that does something.