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"); }