I like to generate XML with the template toolkit (
Template) so that the xml is not litter in my code.
The toolkit has its own little language with statements like FOREACH for iterating and IF for conditionals (it's a bit like Perl, but much simpler).
Sometimes I use Inline::TT which allows me to keep the template in the script. <disclosure>I'm the current maintainer of Inline::TT</disclosure>
Phil