Haven't tested this yet as to whether it makes a difference, but I see you've imported various "standard" functions from CGI.pm by including :standard in the "use CGI qw(:standard);" statement. Because you're using CGI.pm in its object-oriented style (my $cgi = CGI->new() etc.), you don't need to do that, and you might be better off with "use CGI;" instead.