So, you have a template and you want to process it? Template::Toolkit should be useful, if you don't mind changing your template syntax from $substitution to [% substitution %].
Sorry if my advice was wrong.
Comment on Re: Reading from/writing to files with variables substitutions