As you process each line simply push each record onto an array (if the database is small) and compare the record that you're processing at the moment against the list of records that you've already processed. You could make the compare operation a sub. Simply, don't include the records which are duplicates.