#!/usr/bin/perl -w use strict; use warnings; my %hash; while () { my ($coord, $dist) = split; $hash{$coord} = $dist unless defined $hash{$coord} && $dist > $hash{$coord}; } print "$_\t$hash{$_}\n" foreach (sort { $a <=> $b } keys %hash); __DATA__ 567 344 1345 567 2346 78 3456 67 3456 789 4678 45 5349 6 6700 124 6700 50 8964 560 #### #!/usr/bin/perl -w use strict; use warnings; my %hash; while () { my ($coord, @cols) = split; $hash{$coord} = \@cols unless (defined $hash{$coord} && $cols[0] > $hash{$coord}[0]); } print join "\t", qw(coord dist chr exons palindromes), "\n"; print join "\t", $_, @{$hash{$_}},"\n" foreach (sort {$a <=> $b} keys %hash); __DATA__ 567 344 5 7 8 1345 567 5 8 123 2346 78 12 1 567 3456 67 10 1 5 3456 789 10 3 6 4678 45 6 2 0 5349 6 8 2 14 6700 124 13 8 56 6700 50 13 1 4 8964 560 2 18 8