#!/bin/perl use strict; use warnings; use XML::Twig; my %Items; my $twig=XML::Twig->new( twig_handlers => {_all_ => sub {my $ancestors = ($_->ancestors); if ($ancestors =~ m/us:ItemMasterHeader/ ) {my $element_match = ($_->tag); my $coupled = join( ' - ' => $element_match,keys %{$_->atts},values %{$_->atts}),; if (!defined $Items{$coupled}){$Items{$coupled}=1} else {$Items{$coupled}++;} } }, #If element is not in the hash, adds it #If element is in the hash, adds the number of matches to the value print "\n Elements \n \n"; foreach my $k (sort keys %Items) {print "$k => $Items{$k}\n";};