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