The easiest way to not have HTML in the script is to use HTML::Template
It allows you to set up tags in a separate template file (consiting of HTML) and will then insert the values you want into it. Even does loops and if blocks. Very fast and easy to use.