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.