in reply to merge code
The three substitutions replace the first occurrence of each of the patterns. I don't even know if that's possible in a regex.
Consider the case that input data is %EX% %EC% %EX% %BC% - the original code prodcues TOdelete TOdelete %EX% TOdelete for that.
If you really need that behaviour, you can use this:
while(<DATA>){ my %seen; s/(%(?:EX|BC|EC)%)/$seen{$1}++ ? $1 : "TOdelete" /ge; print $_; }
|
|---|