#!/usr/bin/perl use strict; use warnings; use List::Util qw(first); my @array=(); $array[0]= [qw(ape bear cat)]; $array[1] = [qw(dog emu fox)]; $array[2] = [qw(goat horse ibex)]; $array[3] = [qw(mule elephant zebra)]; my $result4 = first{$array[$_][0] =~ /goat/}0..$#array; print $result4."\n"; #prints: 2 # This is logically the same thing, # However, the List::Util function written in C # probably runs much faster foreach my $i (0..$#array) { if ($array[$i][0] =~ /goat/) { print "$i\n"; last; } }