in reply to Recursive loops

Why jump to recursion? I don't see any reason for it in your post. Personally, I'd use a queue for this:
my @queue = (1, 2, 3, 4); while (@queue) { my $current = shift @queue; next unless subA($current); push @queue, subB($current); }
(And don't get in the habit of prefixing your sub calls with &. It's not required in Perl 5+ and has side-effects that you probably don't expect.)