in reply to perl script eats all my PC memory...

I got as far as the third line of your posted code and stopped.
#!/usr/bin/perl # use strict;
You have strict commented out. Why....?

Never mind, uncomment it. Fix your problems bugs. Try it again. Repeat until it compiles cleanly.

Then run it through perltidy. Fix your bugs. Iterate until it's clean as can be.

Now run it and see if it "eats all you memory. If it does, start debugging your logic. Have fun.

I Go Back to Sleep, Now.