if($xref->att('keyref')){ my($h) = $linktext{$xref->att('keyref')}; # the keyref att is the key previously defined for the %linktext hash my($count); foreach my $i (@$h){ $count++; print "child $count:\n"; $i->print; print $/; $xref->copy->paste(last_child=>$i); # this is where I must be doing something wrong! } $xref->print; }