use strict; use warnings; use Data::Dump; use List::Util qw( any ); my @choices = qw/Apple Banana Tiger Lion Cat Turtle/; my @Single = qw/Apple Turtle/; my @Double = qw/Apple Lion/; my %choices; for my $field (@choices) { my $flag = 0; $flag = 1 if any { $_ eq $field } @Single; $flag += 2 if any { $_ eq $field } @Double; $choices{$field} = $flag; } # $flag == 3 means $field is present in both @Single and @Double dd \%choices;