use List::MoreUtils qw(any); #instead of using: # "if (grep( m/whatever/, @list)){}" #use: "if (any { m/whatever/} @list){}" #this exits on the first occurrence. if (!any {m/^\Q$record[3]\E$} @esList){ #the \Q\E guarantees that the value held in the $record[3] #is not interpreted as a regular expression push (@esList = $record[3]); } ### @esList is now a unique list of the values you want... #### my %esList = (); $esList{$record[3]) = 1; ### then to recall all the found records: foreach my $result {sort(keys(%esList))){ print "found record: $result \n"; }