Did you try using a module like XML::Smart?

search.cpan.org/perldoc?XML::Smart