in reply to I know this code could be better...

After a first glimpse, I'd change this code:
#do the output if($is_script eq 'yes'){ middle(); bottom(); } else { top(); middle(); bottom(); }
to something like this:
top() unless $is_script eq 'yes'; middle(); bottom();

Update: petdance said the same thing explaining it. I didn't noticed his reply (probably he submitted it while I was preparing this one)

You could also consider taking a look at Template as I'm doing in these days. It seems interesting since it lets you separate the logic from the presentation. But this topic has been already discussed in the monastery (Web Application Frameworks and their Templating Engines with a Comparative Study of Template and HTML::Template).