in reply to Template with optional PHP execution
I would have a look a HTML::Template, Template::Toolkit and HTML::Mason in rough complexity order. There are also tutorials on templating here on PM.
Everyone writes a templating system at some time or another and (almost) everyone eventually comes to the realisation that one of the modular options does it better. All except the guys that wrote the modules of course :-)
Welcome to Perl Monks BTW. cheers