The bit about 'increment serial number until it's unique' throws a red flag for me. There are two solutions that come to mind. Either put things in a nice relational database (especially one that has a feature like auto-increment id column) or find some other sort of unique identifier.
If you're creating a new hash already, you can use its reference (yes, you read that right) as a unique ID. (I've seen this used as keys for a Flyweight object, pretty cool!) They're guaranteed to be unique, as they have something or other :) to do with memory locations:
]$ perl
my $h_ref = {};
print "$h_ref\n";
HASH(0x80d761c)
You can get rid of everything except the hex digits with a simple
tr/// statement:
tr/a-f0-9//dc;.
That's quicker than scanning for unique numbers.
Still, there's something I can't quite put my finger on here... perhaps you could show us your intended data structure?