my $result2 = (map { $array[$_][0] =~ /goat/ ? $_ : () } 0..$#array)[0]; my $result3 = (grep { $array[$_][0] =~ /goat/ } 0..$#array)[0];