use strict; use warnings; use XML::LibXML; my $xml1 = < matching text other text other text XML my $xml2 = < matching text another text other text XML my $parser = XML::LibXML->new(); my $doc1 = $parser->parse_string($xml1); my $doc2 = $parser->parse_string($xml2); my @doc1Nodes = map {[$_->textContent(), $_->nodeName()]} grep {$_->nodeName() =~ /^element/} map {$_->childNodes()} $doc1->findnodes('//doc/id/elements'); my @doc2Nodes = map {[$_->textContent(), $_->nodeName()]} grep {$_->nodeName() =~ /^element/} map {$_->childNodes()} $doc2->findnodes('//doc/id/elements'); for my $index (0 .. $#doc1Nodes) { print "Mismatch in $doc1Nodes[$index][1]\n" if $doc1Nodes[$index][0] ne $doc2Nodes[$index][0]; } #### Mismatch in element2