my @list = qw(just remember in perl there's more than one way to do it, not that you should do it any way.); my $i = 0; my %hash = map { $_ => ++$i } @list; my @search = ('to','just', 'should', 'one'); my @indices = grep { $hash{$_} } @search; print 'matches ' . join (", ", map { $_ => ord()-97 } map { (a...z)[$hash{$_}-1] } @indices);