in reply to Replacing things in XML files

Given your desire to preserve indentation, comments etc, XML::Simple is definitely not what you want. I'd recommend XML-LibXML. This node compares the code required to complete various tasks using XML::Simple and XML::LibXML.