#!/usr/bin/perl my %dict; # the hash while (my $line = ) { chomp $line; $dict{$line}++; # instead of ++ you could also assign some value... } my @inputs = qw( foo fooed fooen prefoo postfoo ); for my $input (@inputs) { print "found '$input' in lexicon\n" if exists $dict{$input}; } # I'm using the special DATA filehandle here to be able to inline it... # That would be your DICTE handle supplying all the precomputed 385090 lines __DATA__ foo prefoo bar baz ...