It is very easy in Perl to write a little-bit of code that does something in a very inefficient way. What you are asking the computer to do is to iterate sequentially through up to 4,000 records, 5 million times. You do the math. What is plowing you under the ground is virtual-memory overhead,