You're right about putting the longest strings first, if one searched string can be the start of another. That would be my $pattern = join "|", map quotemeta, sort {length $b <=> length $a} keys %replacements;.
With a single substitution operator you don't have to look for the presence of a searched string inside a replacement, because perl will only keep searching after the replaced item, so you can't replace part of a replacement.
In reply to Re^3: string replacement
by Eily
in thread string replacement
by colox
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |