use strict; use warnings; use XML::Twig; my $twiga=XML::Twig->new(); # create the twig for data1 $twiga->parsefile( 'data1.xml'); # build it my $twigb=XML::Twig->new(); # create the twig for data2 $twigb->parsefile( 'data2.xml'); # build it foreach my $t ($twiga->get_xpath('//host[@id]')) { my $att = $t->{'att'}->{'id'}; unless ($twigb->get_xpath("//host[\@id='$att']")) { print "$att is not found in data2.xml\n"; } foreach my $alias ($t->findnodes("host-alias")) { my $web = $alias->text; unless ($twigb->get_xpath("//host[\@id='$att']/host-alias[string()='$web']")) { print "$att with $web is not found in data2.xml\n" } } }