use Math::Combinatorics; for (`cat /usr/share/dict/words`) { chomp; $real_words{$_}++ } while () { chomp; my @letters = split //; foreach my $word_len (1 .. @letters) { foreach my $combination (combine($word_len, @letters)) { foreach my $permutation (permute(@$combination)) { my $word = join '', @$permutation; print "$word\n" if $real_words{$word}; } } } }