use List::Util 'first'; my $first_index = first { test( $arr[ $_ ] ) } 0..$#arr;