You are searching for nodes with
//. It starts from the top and seraches everywhere. That is not what you want. Start your XPath expressions (except the first one) with
.// and add the second argument to
find - the context node. The loop variable of the nearest higher loop should be the context node. The loop entrances will look like this:
for my $Transaction835 ($xp->find('//Transaction835')->get_nodelist) {
...
for my $ClaimPaymentInformationLoop ($xp->find('.//ClaimPaymentInf
+ormationLoop', $Transaction835)->get_nodelist) {
...
for my $ServicePaymentInformationLoop ($xp->find('.//ServicePa
+ymentInformation', $ClaimPaymentInformationLoop)->get_nodelist) {