{ "aesG gly4" => 2, "aesG phil" => 2, "aesG tomD" => 2, "gly4 phil" => 2, "gly4 tomD" => 3, "phil tomD" => 2, } #### use Data::Dump "pp"; my %count; while() { chomp; @keys= sort split; for my $a (0..$#keys){ for my $b ($a+1.. $#keys) { # pp [$keys[$a],$keys[$b]]; $count{$keys[$a],$keys[$b]}++ } } } pp \%count; __DATA__ tomD gly4 phil aesG tomD gly4 phil aesG phil aesG tomD gly4 #### { "aesG\34gly4" => 2, "aesG\34phil" => 2, "aesG\34tomD" => 2, "gly4\34phil" => 2, "gly4\34tomD" => 3, "phil\34tomD" => 2, }