Use split to split the records, and store them in hashes. Then when you process the next file, look into you hash to see if that key has already been encountered.
With this scheme you can solve (nearly) all the "find duplicates", "remove duplicates" and "replace duplicates" problems.
Comment on Re: replace data based on duplicate in another file