my %greater; for my $i (0 .. $#chr_pos_all_strs - 1) { for my $j ($i + 1 .. $#chr_pos_all_strs) { # Skip pairs not 100% > or < each other my $gt = is_greater(@chr_pos_all_strs[$i, $j]) or next; # Always order the pairs correctly my ($lg, $sm) = $gt == 1 ? ($i, $j) : ($j, $i); # Keep track of the new pile count for the anchor ++$greater{$chr_pos_all_strs[$sm]}[CNT]; # Add the mapping to the rest of the pile push @{$greater{$chr_pos_all_strs[$sm]}[NODE]}, "$chr_pos_all_strs[$lg]"; } } sub is_greater { my ($ref1, $ref2) = @_; # Determine if the first value is greater or smaller # Return false if they are equal (can't be > or <) my $cmp = $ref1->[0] <=> $ref2->[0] or return; # For the remaining values, verify that each position # is the same as the first (> or <) # Return false otherwise ($ref1->[$_] <=> $ref2->[$_]) == $cmp || return for 1 .. $#$ref1; # Return which was greater return $cmp; }