in reply to Using Perl to create XML

The interface isn't quite like what you're asking about, but have you checked out XML::Writer?

Example from the docs:

use XML::Writer; use IO; my $output = new IO::File(">output.xml"); my $writer = new XML::Writer(OUTPUT => $output); $writer->startTag("greeting", "class" => "simple"); $writer->characters("Hello, world!"); $writer->endTag("greeting"); $writer->end(); $output->close();