in reply to Premature end of script

This is a helpful checklist by Tom Christiansen. It might give you some hints:

http://www.perl.com/doc/FAQs/cgi/idiots-guide.html

a version which perhaps outputs an image header when creating the object..

Try putting your header in the very beginning of the script, and use $| = 1