pack 'L',$number
but this will fail if you have any numbers bigger than 4294967295 (2**32-1), in which case, barring any knowledge of large, unused ranges, 5 bytes is the best you're going to do, and you may as well be doing
pack 'H10',$number
However, instead of trying to compress things, you might be better off using an off-line algorithm that doesn't require everything being in memory at once, e.g.,
- open 16 new files for writing
- go through the array sequentially, copy each record to a randomly chosen file of the 16.
- close all of the files
- randomize each file (~7M) separately
- concatenate