XML::Dumper is a Perl module for dumping Perl objects from/to XML.
# ===== Using an object
$dump = new XML::Dumper;
$xml = $dump->pl2xml( $perl );
$perl = $dump->xml2pl( $xml );
$dump->pl2xml( $perl, "my_perl_data.xml.gz" );
# ===== Using function calls
$xml = pl2xml( $perl );
$perl = xml2pl( $xml );
XML::Dumper dumps Perl data to XML format. XML::Dumper can also read XML data that was previously dumped by the module and convert it back to Perl. You can use the module read the XML from a file and write the XML to a file. Perl objects are blessed back to their original packaging; if the modules are installed on the system where the perl objects are reconstituted from xml, they will behave as expected. Intuitively, if the perl objects are converted and reconstituted in the same environment, all should be well. And it is.
Additionally, because XML benefits so nicely from compression, XML::Dumper understands gzipped XML files. It does so with an optional dependency on Compress::Zlib. So, if you dump a Perl variable with a file that has an extension of '.xml.gz', it will store and compress the file in gzipped format. Likewise, if you read a file with the extension '.xml.gz', it will uncompress the file in memory before parsing the XML back into a Perl variable.
Another fine challenge that this module rises to meet is that it understands circular definitions and multiple references to a single object. This includes doubly-linked lists, circular references, and the so-called 'Flyweight' pattern of Object Oriented programming. So it can take the gnarliest of your perl data, and should do just fine.
One caveat; XML::Dumper does not handle binary data. There have been discussions in the expat mailing list archives discussing the challenges associated with encoding binary data with XML. I chose the cowardly path of making the problem a non-issue by not addressing it. To store binary data, one could encode the data into ASCII before encapsulating the data as XML, and then reverse the process to restore the data. There are several Perl modules that one can use for this, Convert::UU, for example.