#!/usr/bin/perl use warnings; use strict; my %uniq; while () { next unless /^\s*\d/; chomp; my $line = $_; my @f = split /,/, $line; my $key = $f[1].$f[2].$f[3]; if ( exists $uniq{$key} ) { my $stored = ( split /,/, $uniq{$key})[4]; my $new = $f[4]; if ($new lt $stored) { $uniq{$key} = $line; } } else { $uniq{$key} = $line; } } print $_."\n" for (values %uniq); __DATA__ 1,ken,james,smith,s 11,ken,james,smith,f 0,ken,james,smith,s 5,ken,arthur,wesson,g 7,ken,arthur,wesson,a