use strict; use warnings; use List::Util qw(first); my @array_to_search = (1..5) x 2; my $target_value = 3; my @target_values = (5, 4); { # Find the first target and do something to it. my $match = first { $target_value == $_ } @array_to_search; matches_found( $match ); } { # Find all matches and do stuff. my @matches = grep { $target_value == $_ } @array_to_search; matches_found( @matches ); } { # match list with nested loop matching my @matches; foreach my $target ( @target_values ) { push @matches, grep { $target_value == $_ } @array_to_search; } matches_found( @matches ); } { # match list with a hash lookup my %target; @target{ @target_values } = (); my @matches = grep { exists $target{$_} } @array_to_search; matches_found( @matches ); }