Have a look at the various templating packages. I personally like very much Template::Toolkit: I find it very flexible, easy to learn and it has lots of additional extensions.
CountZero
"If you have four groups working on a compiler, you'll get a 4-pass compiler." - Conway's Law