in reply to How do I speed this up?

Hmmm....

If you're doing this repeatedly you can use my Text::Boilerplate module.
http://www.perl.com/CPAN-local//authors/id/S/ST/STEPHEN/Text-Boilerplate-0.08.tar.gz

Boilerplate will let you put things like Foo is [* "foo" *] in your text and will generate an anonymous sub to turn this template into text. It avoids re-doing the replace every time, that way. Of course, you do pay the penalty of doing the original processing...

Otherwise, you can try Text::Vpp.

Hmm... another possibility, similar to above ones... I don't know whether this will speed things up, slow them down, or even work at all, but try it:

%constants = ( 'foo' => 'bar', 'baz' => 'bap' ); $pattern = join('|', map(quotemeta($_), keys %constants) ); eval("s{($pattern)}{\$constants{\$1)}e");

stephen