my $pattern = join "|", map quotemeta, keys %replacements;
I think it would be good to also sort on length, as I discussed in Building Regex Alternations Dynamically. Although huck does make a good point that preserving the original ordering may be important too. Update after your reply: Good point about replacements within the replacements, whether the OP wants that or not and which method is more appropriate will depend on their requirements.
In reply to Re^2: string replacement
by haukex
in thread string replacement
by colox
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |