in reply to regexp trouble...

This would match all instances of $whatever that wasn't immediately following a \, I think. It wouldn't be the fastest regexp in the world...
s/[^\\]?\$(\w+)/${$1}/g
I haven't tested it myself, of course... Text::Template is a CPAN module that may well do everything you need, and more, however.