my $B = $doc->selectNodes("A/B")->[$cpt]->nodeValue(); my $D = $doc->selectNodes("A/C/D")->[$cpt]->nodeValue(); #### if(defined($A_list)){ for my $cpt (0..$#$A_list) { ... } print "\n\n"; }