my @slot = qw[ A A B B C C B B ]; my %slot_mask; # Create a hash based on the input names. Each hash entry # contains a single binary sequence for the "slot" numbers # that are specified earliner in @slot foreach (0..$#slot) { # Create a "blank" scalar if none is defined already unless (defined($slot_mask{$slot[$_]}) { $slot_mask{$slot[$_]} = ''; } # Set this particular bit to 1 using an assignment vec($slot_mask{$slot[$_]}, $_, 1) = 1; } # Retrieval, as per your example, for the 1st slot if ($slot_mask{A} & 0b00000010) { print "1st is A...\n"; } # Same idea but with the shift operator that is less prone # to typographical errors if ($slot_mask{A} & (1 << 1)) { print "1st is A...\n"; } # And likewise for the 4th or what have you, but this time # using the vec() function if (vec($slot_mask{A}, 4, 1)) { print "4th is A...\n"; }