sub pro { my $self = shift; sub attr { my $node = shift; my $map = $node->getAttributes; my @tmp = %$map; while ( my ( $key, $value ) = each %$map ) { next unless ( ref( $value ) eq 'XML::DOM::Attr' ); my $val = $value->getValue; return "\[\@$key=\'$val\'\]"; } return undef; } sub trace { my $node = shift; my $attr = attr($node); # base case if ( $node->getParentNode->getNodeType == 9 ) { $attr ? return "//" . $node->getNodeName . $attr : return "//" . $node->getNodeName; } # return unique path $attr ? return trace( $node->getParentNode ) . "/" . $node->getNodeName . $attr : return trace( $node->getParentNode ) . "/" . $node->getNodeName; } # "main" my @paths = map { trace($_) } $self->{'xml1'}->findnodes( '//*' ); print join "\n", @paths; exit; for my $path ( @paths ) { print "\nPath: ", $path; for ( $self->{'xml2'}->findnodes( $path ) ) { print "\nFound node: ", $_->getNodeName; print "\thas Value: ", $_->getFirstChild->getNodeValue if $_->getFirstChild; } } }