500
‘Premature end of scrip headers’ error message refers to the script being stopped for whatever reason before it actually return any output to the browser.
The first time to check is to ensure the below codes are output first
print "Content-type: text/html\n\n";
And then to debug the error, simply add the below line(preferably after the above code).
use CGI::Carp qw(fatalsToBrowser);