use strict; use warnings; my $word = shift || 'OLHOSC'; my $fname = sprintf 'length%02d.txt', length $word; # eg. length06.txt my $word_key = join '', sort split //, lc $word; # sort lowercase letters open my $fh, '<', $fname or die "sorry, no such word list available, Bye!"; while( my $line = <$fh> ) { chomp $line; my $dict_key = join '', sort split //, lc $line; print "$word => $line\n" if $dict_key eq $word_key # bail out here - if only one match is needed } close $fh;