in reply to Premature end of script header error

Try adding the following line to your program before outputing any html.
print "Content-type: text/html\n\n";