I mean you have a data-structure and want it to become XML. So create a function that will produce XML. It may be extra typing than using a module like XML::Twig, but it's the most reliable way. If you want to be smart, make your data-structure a class and add a toXML-method to it.