There's plenty of material on this site that should help you with your questions.
I am about to write my very own templating module.. mentions
CGI::FastTemplate: the discussion that follows considers various templating systems in detail.
Web Application Frameworks and their Templating Engines with a Comparative Study of Template and HTML::Template compares several templating systems. Personally, I would go with
Template for an extensible and flexible system, but plenty of excellent alternatives exist (see also
XSLT vs Templating? and
XSLT vs Templating, Part 2).