I agree with friedo. A template is the right way to go. The solution from Corion will work fine, but you may also want to look at How do I avoid double substitution when replacing many patterns?
In reply to Re: Regex to replace $vars with subroutine
by kyle
in thread Regex to replace $vars with subroutine
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |