in reply to Keep file formatted

To simplify your regular expressions, you can use an alternate delimiter, such as:
s#<FOO>#<B>Foo</B>#g;
I try and use something that won't show up in the substitution, so that you don't have to backslash everything.