in reply to XML::XPath and variables

You need to escape the the @'s where they are in XPath symbols. Perl is trying to interpolate arrays there and coming up empty.

@nodes = $xp->findnodes( "//A[$save = \@idref]//B[\@id = $save]" );

After Compline,
Zaxo