the cgi-lib.pl script provides many useful routines.
It is free (as usual) and often comes with Perl
or can be downloaded from various places including
the cgi-lib.pl Home Page at http://cgi-lib.stanford.edu/cgi-lib/ .