http://www.perlmonks.org?node_id=690746


in reply to Regex to replace $vars with subroutine

The proper way to do this is with one of the many templating modules that exist on CPAN, such as HTML::Template. But if you truly want to roll your own, you can use the /e option on your regex (see perlre) to make the replacement string executable code.
  • Comment on Re: Regex to replace $vars with subroutine