$explored->{$node->{_id}}++; foreach my $link (@{$node->{_outlinks}}) { $do_search->($link->{_to}) unless ($explored->{$link->{_to}{_id}}); # we stored the node id, not the link id in $explored ^^^^^ }