in reply to code problem

If you can't get to the server's error logs, write a short shell script wrapper to see what the error is:
#!/bin/sh -x

printf "Content-type: text/plain\n\n"
exec 2>&1

./your_script

One thing that occured to me is that perhaps the path to Perl at the top is wrong.