$hash{$Query}[3] = $one; $hash{$Query}[4] = $two; #### while () { my ($Query, $Score, $Start, $End, $one, $two) = split; my $aref=[$Score, $Start, $End, $one, $two]; if ( ! exists ( $hash{$Query} ) ) { $hash{$Query} = $aref; } else { if ( $hash{$Query}[1] > $Start ) { $hash{$Query} = $aref; } } if ( ! exists ( $hash2{$Query} ) ) { $hash2{$Query}= $aref; } else { if ( $hash2{$Query}[2] < $End ) { $hash2{$Query} = $aref; } } }