Thanks, that clears up most things.
I did know how post-increment works on numerical scalars, but this sort of use is new to me, and the perlop page says nothing about adding new records to a hash with ++... But this is what it seems to do.
Your code works a treat, and the memory use doesn't seem to be too bad. Thanks.