use strict; use warnings; my $dict = '/usr/share/dict/words'; # Do not space-separate the word in this version. my $scrambled_word = shift or die "Must specify a word\n"; my $scrambled_length = length $scrambled_word; my $scrambled_sorted = join '', sort split '', $scrambled_word; my $pattern = qr{ \A (?: [$scrambled_word]{$scrambled_length} ) \n \z }x; open DICT, '<', $dict or die "Cannot open '$dict': $!"; while () { next unless /$pattern/o; chomp; my $sorted = join '', sort split '', $_; next unless $sorted eq $scrambled_sorted; print "$_\n"; } close DICT or warn;