in reply to Tips on how to perform this substitution?

Another useful thing to do here is to use the g and c modifiers. From perldoc perlre:
g and c
Global matching, and keep the Current position after failed matching. Unlike i, m, s and x, these two flags affect the way the regex is used rather than the regex itself. See "Using regular expressions in Perl" in perlretut for further explanation of the g and c modifiers.
The difference here is that, when you use these two modifiers together, you can loop across the string repeatedly (an internal cursor advances down the string), and you can try different things to see if any of them match, e.g. in an if..elsif structure. No, this is not minimalist; it is not "golf." But it can come in handy in situations like this, where a single regular-expression might not be easy to construct and verify, but a short loop and if-statements are clear.
  • Comment on Re: Tips on how to perform this substitution?