my %words; { open my $fh, '<', '/path/to/dict.txt' or die $!; while <$fh> { chomp; my $key = join '', sort split ''; push @{$words{$key}}, $_; } }