in reply to Cookies messing up code

Simple - the print header(...) calls your own header() function. This function only executes a print, whose return value, 1, is passed back to the calling code, which happens to be a print itself and so outputs that 1.

Two suggestions: use the object oriented interface to CGI as it's much cleaner, and really do use a templating system to pull all the HTML out of your script. I propose the excellent Template Toolkit 2 module. See also perrin's templating system roundup at Perl.com

Makeshifts last the longest.