in reply to Poorly written script

You would benefit from using a Templating System, such as (any one of)

There are literally hundreds of posts related to templating here, as a simple search will reveal. Be also sure to read the Choosing a Templating System, (perl.com article).

--
Andreas