I try to keep HTML seperate from my code, using
HTML::Template and
<TMPL_IF NAME="__first__">,
<TMPL_IF NAME="__odd__"> etc you can achieve this sort of result. Check out the
documentation from examples.
Hope this helps
Update:Slight rewording and link to the docs.
Martin