sub canonize { return join '', sort split //, lc $_[0]; } my %dict; { open(my $fh, '<', $dict_file) or die("Unable to open dictionary file \"$dict_file\": $!\n"); while (<$fh>) { chomp; push @{ $dict{canonize($_)} }, $_; } } my $jumble = 'OLHOSC'; $jumble = canonize($jumble); if (exists($dict{$jumble})) { print("$_\n") for @{ $dict{$jumble} }; } else { print("No matches found.\n"); } #### sub canonize { return join '', sort split //, lc $_[0]; } my $jumble = 'OLHOSC'; open(my $fh, '<', $dict_file) or die("Unable to open dictionary file \"$dict_file\": $!\n"); my $found = 0; $jumble = canonize($jumble); while (<$fh>) { chomp; if (canonize($_) eq $jumble) { print("$_\n"); $found = 1; last; } } if (!$found) { print("No matches found.\n"); }