in reply to Re^2: string replacement
in thread string replacement

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.