in reply to rough approximation to pattern matching using local

You already got some ansers, but I can't resist to chime in :-)

You haven't exactly told us what you want to achieve. It looks to me like what you want is not necessarily RegExes, but a kind of template toolkit / templating engine.

Anyway, if you want to follow your initial approach (even if for learning purposes), you should at least read through

These texts are Perl centered, but contain basics that are valid for any programming language.

  • Comment on Re: rough approximation to pattern matching using local