foreach (@data) { ($id,$var2,$var3,$var4,$var5) = split( /,/, $_); $id = grep { m/$id$/ } @data2; print "This $id was not found.\n"; }