#!/bin/perl use strict; use warnings; use XML::Twig; use Tie::IxHash; my %Items; tie %Items, "Tie::IxHash"; my $xml = < XML my $twig = XML::Twig->new( twig_handlers => { _all_ => \&handler, } ); $twig->parse($xml); # build it $twig->purge; # clear end of document from memory print "\n"; print "$_ => $Items{$_}\n" for keys %Items; sub handler { my $Item_master_Ancestory = $_->ancestors; my $element_match = $_->tag; my $text = $_->trimmed_text; my $coupled = join ' - ', " " x $Item_master_Ancestory, $element_match, keys %{ $_->atts }, values %{ $_->atts }, $text; ++$Items{$coupled}; print "$coupled: $Items{$coupled}\n"; }