use strict; use warnings; my @choices = qw/Apple Banana Tiger Lion Cat Turtle/; # Big array with 150 elements my @Single = qw/Apple Turtle/; my @Double = qw/Lion/; foreach(@choices){ my $field = $_; if (grep {$_ eq $field} @Single) { $flag =1; } elsif (grep {$_ eq $field} @Double) { $flag =2; } else{ $flag =0; } }