use List::Util 'first'; sub find_first_index { my $target = shift; first { $_[$_] eq $target } 0 .. $#_; } # Simple enough to write inline: my $idx = first { $ary[$_] eq $target } 0 .. $#ary;