Very interesting. I was able to reproduce the OOM error with my cygwin perl, and the two modifications you mentioned to avoid OOM worked for me also. Strangely, when I watch the perl process in the task manager, or just watch the total Memory usage it never varies. On my system the process reaches about 230 MB memory usage and the total memory stays at about 15.3 GB total over the whole execution. It seems that it might suddenly encounter a memory leak that happens so fast that the task manager doesn't detect it before the process dies. On my system the time between the start of the loop that produces the OOM and the exception is about 22 seconds.