in reply to calling subroutine inside loop - ERROR - subroutine executes only once

This line dies at the second loop

chdir($corner) or die "\n $!\n"

And it tells you why, it couldn't find the path.

No such file or directory

You are trying to descend successively into /file/path/is/AAA/BBB/CCC/DDD but BBB is on the same level like AAA not deeper!

Cheers Rolf

(addicted to the Perl Programming Language and ☆☆☆☆ :)