#!/usr/bin/perl open(FH, $ARGV[0]) || die("Cannot open:$!"); while () { ($Query, $Score, $Start, $End, $one, $two) = split; if ( ! exists ( $hash{$Query} ) ) { $hash{$Query}[0] = $Score; $hash{$Query}[1] = $Start; $hash{$Query}[2] = $End; $hash{$Query}[3] = $one; $hash{$Query}[4] = $two; } else { if ( $hash{$Query}[1] > $Start ) { $hash{$Query}[0] = $Score; $hash{$Query}[1] = $Start; $hash{$Query}[2] = $End; $hash{$Query}[3] = $one; $hash{$Query}[4] = $two; } } if ( ! exists ( $hash2{$Query} ) ) { $hash2{$Query}[0] = $Score; $hash2{$Query}[1] = $Start; $hash2{$Query}[2] = $End; $hash{$Query}[3] = $one; $hash{$Query}[4] = $two; } else { if ( $hash2{$Query}[2] < $End ) { $hash2{$Query}[0] = $Score; $hash2{$Query}[1] = $Start; $hash2{$Query}[2] = $End; $hash{$Query}[3] = $one; $hash{$Query}[4] = $two; } } } foreach $Query ( keys (%hash) ) { foreach $Query ( keys (%hash2) ) { print "$Query\t$hash{$Query}[0]\t$hash{$Query}[1]\t$hash2{$Query}[2]\t$hash{$Query}[3]\t$hash{$Query}[4]\n"; } } close(FH); __DATA__ Books 6 159290954 159291342 + Author Books 6 159294558 159294653 + Author Books 6 159316253 159316398 + Author Books 6 159330999 159331385 + Author Books 6 159290971 159290997 + Author Books 6 159316253 159316398 + Author Books 6 159330999 159331289 + Author Books 6 159316268 159316398 + Author Books 6 159330999 159331245 + Author