Have a look at this thread Limit the size of a hash.
In reply to Re: sorting array of arrays reference by hdb in thread sorting array of arrays reference by kimlid2810