in reply to H of A optimization

I have a loop here, that is requiring a lot of time to run.

Since the point of the loop is to look for cycles, stop as soon as you find one.

SEARCH: foreach my $item (keys %edgeHash){ foreach my $item2(@{$edgeHash{$item}}){ if($item2 eq $b){ $good = "0"; last SEARCH; # one is enough, stop now. } } }