if you want a good answer, you need to be careful to phrase the question well. the original question talks of 6000 records, but then the example uses 5 million records.
as everybody has been trying to get across...the buffering in perl, and in all computer languages and operating systems that support buffering, has to do with input/output, and absolutely nothing to do with memory structures.
also the example code creates a rather useless (huge) array of elements that can be computed on the fly, without ever creating an array in the first place. was this the intention of the question?
the hardest line to type correctly is: stty erase ^H