in reply to Premature end of script headers (i know, i know...)

The problem isn't that you have to do the headers before you do anything, it's that you have to print the headers before you print anything else to STDOUT. What is probably happening is that some of your earlier code is producing an error message, which is causing the headers to end early. Try using use CGI::Carp 'fatalsToBrowser'; which will cause the script to generate headers on demand if there is an error, so the error message will be visible in your browser, and check apache's error log to find out what the error message is that is being produced.