my $twig= XML::Twig->new( TwigHandlers => { Id => \&id_Tag } ); #actually parse the file $twig->parsefile($xml_file) or die "cannot parse [$xml_file]: $!"; ########################################### sub id_Tag { ########################################### my($t, $idTag)= @_; my $id = $idTag->first_child('Item'); $idText = $id->{'att'}->{'TaxId'}; print "TAX_ID: ",$idText,"\n"; # Release memory of processed tree up to here $t->purge(); }