use strict; use warnings; use XML::Simple qw( XMLout ); use XML::LibXML qw( ); my $perl_datastructure = { Root => { 'PersonA' => { Pets => [qw( PetA PetB )], }, 'PersonB' => [ { Pets => 'PetAA', }, { Pets => 'PetBB', }, ], }, }; my $xml = XMLout($perl_datastructure, NoAttr => 1, KeepRoot => 1); my $parser = XML::LibXML->new(); my $doc = $parser->parse_string($xml); my $root = $doc->documentElement(); print $_->textContent(), "\n" for $root->findnodes('/Root/PersonA/Pets'); print("--\n"); print $_->textContent(), "\n" for $root->findnodes('/Root/PersonB/Pets');