unless ($hash{$new_id}++) { # INSERT $row into the new table $new_sth->execute( ... ); } else { # possibly fetch existing row and check to see # if this redundant old row has better data } }