Like the good monks have been telling you, use a templating system like HTML::Template and a lot of your issues will dissolve away. Get the HTML out of your CGI. It's sooooo much easier.
—Brad "The important work of moving the world forward does not wait to be done by perfect men." George Eliot