in reply to Perl hangs with specific folders

I suggest you learn about the debugger. It would allow you to execute each line of your program (or parts of your program) one at a time, and inspect the values of variables to confirm that things are happening as you expect.

1 Peter 4:10