#!/usr/bin/perl -w use strict; my %idhash; my @ids; foreach (@id_list){ #split up your input line into something useful @ids = split (/-->/,$_); # check to see if that date is already in your hash and if it is newer if(defined($idhash{$ids[1]}) && $idhash{$ids[1]} >= $ids[2]){ next }else{ #populate your hash $idhash{$ids[1]} = $ids[2]; } } #then print your dates from the hash using foreach key