my %hash; while (<>) { my ($chain, $pos, $zcoor) = (split)[4, 5, 8]; $hash{$chain} = [$pos, $zcoor] if not exists $hash{$chain} or $pos < $hash{$chain}[0]; }