my %word; { open my $fh, '<', '/path/to/wordlist.txt' or die $!; chomp( my @words = <$fh>); close $fh or die $!; @word{@words} = (); } # ... then when it's time to look up a word, if (exists $word{$foo}) { # ... }