in reply to Replacing things in XML files

I'm not sure about keeping the actual formating (indents, line breaks, comments), but what you're basically looking for is XSLT.

There exists in CPAN a few different XSLT modules (XML::XSLT, XML::LibXSLT, XML::ApplyXSLT), but I've never used any of them.

(I do enough XML work that I know of XSLT, yet never used it directly)