#comma delimited user input @words = split(/,/, $words); #copy of array for later @words2 = @words; open FH, "$data" or die "Can't open $data: $!"; flock (FH, 1) or die "Can't lock $data for reading: $!"; my @all = ; close FH; #iterate through user input comparing with db while (@words) { my $item = shift (@words); $count++; foreach my $line (@all) { ($one,$two,undef,$four,$spare_1,$spare_2) = split "\t",$line; chomp; if ($item eq "$four") { push (@matched, $item); push (@counted, $count); last; } } } #iterate through @counted applying undef to matched items in copy of user input array while (@counted) { my $item = shift (@counted); $words2[$item -1] = undef; } #remove undef items from user input leaving only unmatched items. foreach my $item (@words2) { unless ($item eq "") { push (@uniq, $item); } } #@matched contains only matched items #@uniq contains only unmatched items