You can download lots of examples and working CGI programs from the Web. Here are some places to look:
http://www.yahoo.com/Computers_and_Internet/Internet/ World_Wide_Web/CGI___Common_Gateway_Interface/
ftp://ftp.ncsa.uiuc.edu/Web/httpd/Unix/ncsa_httpd/cgi/
http://www.seas.upenn.edu/~mengwong/perlhtml.html
http://www.charm.net/~web/Vlib/Providers/CGI.html
http://www-genome.wi.mit.edu/WWW/tools/scripting/