#!/usr/bin/perl use strict; use warnings; my @set = qw(one bright day in the middle of the night); my %pos; # Preprocess @set { no warnings 'uninitialized'; vec( $pos{ ord( $set[ $_ ] ) }, $_, 1 ) = 1 for 0 .. $#set; } while ( my $val = ) { chomp $val; my $bitstr = $pos{ ord( $val ) } or next; my $i = length( $bitstr ) * 8 - 1; while ( $i-- ) { print "$val\n" and last if vec($bitstr, $i, 1) && $val eq $set[ $i ]; } } __DATA__ one two buckle my shoe the cat in the hat