while () { chomp; my $key = lc $_; next if $seen{$key}++; my $signature = join "", sort split //, $key; push @{$words{$signature}}, $_; } for (sort keys %words) { my @list = sort @{$words{$_}}; next unless @list > 1; print "@list\n"; } #### ab aabb aaabbb xxyy xxxyyy #### ab aabb aaabbb xxyy xxxyyy #### #!/usr/bin/perl while () { chomp; my $key = lc $_; next if $seen{$key}++; my @unique = (); my %seenletter = (); my @alphawithdupes = sort split //, $key; foreach my $elem ( @alphawithdupes ) { next if $seenletter { $elem }++; push @unique, $elem; } my $signature = join "", @unique; push @{$words{$signature}}, $_; } for (sort keys %words) { my @list = sort @{$words{$_}}; next unless @list > 1; print "@list\n"; } __END__ ab aabb aaabbb xxyy xxxyyy