use strict; use warnings; my $input = ; my ($re) = map qr/^[$_]*$/, join '', map quotemeta, $input =~ /(.)/g; my $dict = 'wordlist.txt'; open(my $dict_fh, '<', $dict) or die("Unable to open dictionary file: $!\n"); while (<$dict_fh>) { print if /$re/; }