my %anagrams; while (defined( my $dict_word = <> ) ) { my $sorted = sort split //, $dict_word; push @{$anagrams{$sorted}} = $dict_word; }