sub deranged {                          
        my @a = split('', shift);       
        my @b = split('', shift);
        for (0 .. $
                $a[$_] eq $b[$_] and return;
        }
        return 1
}

sub find_deranged {     
        for my $i ( 0 .. $
                for my $j ( $i+1 .. $
                        next unless deranged $_[$i], $_[$j];

                        print "length ", length($_[$i]), ": $_[$i] => $_[$j]\n";
                        return 1;
                }
        }
}

my %letter_list;
open my $in, 'unixdict.txt';

local $/ = undef;

for (split(' ', <$in>)) {
        
        push @{ $letter_list{ join('', sort split('', $_)) } }, $_
}

for (   sort { length($b) <=> length($a) }      
        grep { @{ $letter_list{$_} } > 1 }      
        keys %letter_list               )
{
        
        last if find_deranged(@{ $letter_list{$_} });
}