in reply to Re^8: Avoid keeping larger lists in Memory
in thread Avoid keeping larger lists in Memory

This is pretty good, you captured, I believe, most of the recommended optimizations.

In the beginning of your program, for better efficiency, you should have this line:

my $max = sqrt($num);
after the while loop, so that you better benefit from the size reduction associated with the elimination of the powers of two from the original target number.

In the foreach loop, you could recalculate $max immediately after having modified $num (this will be efficient for some input data, such as the product of two or a few large primes), but, for safety, you would need to restart the foreach loop with a redo. Actually, it would be easier, clearer and safer to rewrite this loop as a while loop.