See List :: MoreUtils . You can do many useful things with arrays without having to run your own version, and also faster (because it is implemented in C / XS):
use List::MoreUtils qw(first_index indexes); my $index_of_matching_element = first_index { /o/ } @list;
For all relevant indices, and then their corresponding elements, you can:
my @matching_indices = indexes { /o/ } @list; my @matching_values = @list[@matching_indices];
or simply:
my @matching_values = grep { /o/ } @list;
Ether
source share