sub find { my $tree = shift; my $node_value=shift; my $last=0; my $child; my $func; $func = sub ($) { $child=shift(); $last=1 if($child->getNodeValue() eq $node_value); my @children=$child->getAllChildren(); $func->(shift(@children)) while(@children && !$last); }; $func->($tree); return $child if($last); return undef; }