#!perl use strict; use warnings; use XML::Twig; use Data::Dump 'pp'; my %hash=(); my $twig = new XML::Twig( twig_handlers =>{ 'SellerInformation' => \&info } ); $twig->parsefile('test.xml'); pp \%hash; sub info { my ($t,$e) = @_; my $id = $e->first_child("Seller")->att('sellerIdFromProvider'); my $col = $e->first_child("TaxableLocationsCollection"); for my $loc ($col->descendants("TaxableLocation")){ push @{$hash{$id}}, $loc->att('locationValue'); } }