Update: I have discontinued work on Text::Document in favour of using Template-Toolkit and my add-on module Text::Smart available from CPAN

Text::Document provides a set of perl modules for manipulating text documents. An advanced templating library allows embedding of conditionals, placeholders, loops and includes in arbitrary text document. While this is very similar to HTML::Template, it serves a wider purpose since it avoids any HTML style syntax. There is also a generic interface for provides dynamic content generators, and an advanced set of modules for transforming so called 'smart text' into an arbitrary markup language.

CGI::Tools is builds on the interfaces provided by Text::Document to provide tools for query validation, form processing and dynamic tree generation.

http://berrange.com/coding/textdoc