Sorry I miss you previous post so with the few elements I have
(500 error and a code snippet)
I can only provide a
common guideline for solving error 500 problem :
Check that the script compile (as tachyon pointed out) (use warnings and use strict and -T never hurt if you got some input)
with perl -cw script.pl
If your script was FTPed from a box with a different OS from the one running on the box where you're executing the script, check for added invisible character (EOL problem for DOS->UNIX transfer...)
Check that the path to perl interpreter is correct (otherwise you'll get a error 500 page and a 'no such file or directory' in your web logs...)
In all case check the HTTP server logs for more detailed error messages.