The second piece of code will basically match all the nulls and put them into an anonymous array and then put the size of that array into $nulls. From a couple of tests I did using Devel::Size, an array with half a million nulls will take up about 320 MB. If you go any larger, this will quickly exhaust memory on a standard computer.
5 million nulls, even if it was double byte should take up less than 10 mb of memory no? If array overhead was double that, we're still at 20 mb of memory per copy?
What is it about the workings of this second statement that causes it to consume so much memory?
I'd like to understand how that works if anyone happens to know.