my $dictionary = '/usr/share/dict/words'; # input letters, changed to lowercase my @letters = split //, lc shift @ARGV; open my $dict_fh, '<', $dictionary or die "Can't read dictionary '$dictionary': $!"; WORD: while ( my $word = lc <$dict_fh> ) { chomp $word; # $word is lowercase with no newline my $orig_word = $word; # for each letter in the search set, for my $letter ( @letters ) { # remove that letter from the dictionary word # and skip to the next word if it's not found next WORD if ! ($word =~ s/$letter//); } # if all the dictionary word's letters were used, # print out the original dictionary word. print "$orig_word\n" if $word eq ''; } close $dict_fh or die "Can't close: $!";