A little more information regarding your record layout would go a long way in helping people help you. If your records are linked to id numbers then you can use a hash with the 'id' as the key and store the record as a string or an array reference as the hash value
my %records;
$records{ $id_number } = "Record for $id_number";
## OR
$records{ $id_number } = ['Record', 'for', $id_number];
This will allow you to lookup id's with complexity O(1) and easily manipulate the corresponding record.
# Assuming the records are stored in @records
for my $record (@records) {
$recStore{$record}++;
}
# To search for a record
my $recToFind = 4343;
my $recExists = $recStore{$recToFind} || 0;
The keys of the hash are the id's retrieved from your database and the corresponding values are the number of times the id was found, so for repeating records $recExists will be greater than 1, and for non-existent records it will be equal to 0. To get a list of all id's sorted numerically you could write
my @sortedID = sort {$a <=> $b} keys %records;