my $next = grepper {$_ == &somethingorother} @array; while (my $found = $next->()) { # ... do something with each match }