The Best way to do what you're trying to would be to look into the CGI module from CPAN. There are all sorts of nifty subs in that module that make any CGIer's life way easier. For instance (from the docs), here's a "Hello World" page done with the functions from CGI.pm:
#!/usr/local/bin/perl
use CGI qw/:standard/; # load standard CGI routines
print header, # create the HTTP header
start_html('hello world'), # start the HTML
h1('hello world'), # level 1 header
end_html; # end the HTML
And the icing on the cake is that CGI should be already installed in your existing distribution of Perl!
LAI
__END__