/mdc/md/mi/mt[contains(.,"VAL")]
####
#!/usr/bin/perl
use warnings;
use strict;
use feature qw{ say };
use XML::LibXML;
my @val;
my $doc = 'XML::LibXML'->load_xml( location => 'file.xml' );
for my $book ($doc->findnodes('/mdc/md/mi/mt[contains(.,"VAL")]')) {
my $order = 1 + $book->findvalue('count(preceding-sibling::mt)');
my $rs = $book->findnodes("../mv/r[$order]");
say join ', ', map $_->textContent, $book, @$rs;
}
####
open file.xml ;
for /mdc/md/mi/mt[xsh:match(.,'^VAL[0-9]+')] {
my $order = 1 + count(preceding-sibling::mt) ;
echo xsh:join(', ', (.), ../mv/r[$order]) ;
}