in reply to how to evaluate a variable in a string?

Get a real templating engine. You're reinventing the wheel, and you're almost certain to reinvent a worse one, as this is actually a very messy problem. Do yourself a favor and look up something like Embperl or Mason.