my @a = ('a'..'j'); my @b = ('j'..'z'); my $a = 0; if (ss_grep('b', \@a) and ss_grep('k', \@b)) { print "Found b and k\n"; } print "$a iterations\n"; sub ss_grep { my ($test, $aref) = @_; for (@$aref) { ++$a; return 1 if $_ eq $test; } 0; }