in reply to Malformed Header?

You need to add
print "Content-type: text/html\n\n";
before the
print "test\n";

You could check this simple article in devdaily.com, the Common Gateway Interface specification and, if you can, the use of CGI.pm

This sorry excuse for a monk would also sugest a switch from cgi to mod_perl, for better performance and more features, in the long run, if you could get the apache admin to set it up

Update: and you should drink from the monks knowledge in the Q&A about CGI programming