That shows a lot of Perl code, but it doesn't explain what you're trying to do.
We need to know what your *input* is, and what you want as *output*. What directories or files are you sending in? What directories or files do you want out?
That's reasonably intermediate Perl code there with a lot of hack comments and other such things (definitely kudos for at a glance appearing strict, and 3-arg open), so you can't just expect to throw it up on Perlmonks and think we'll know what you're trying to do with it.
Start over. Tell us your problem statement. "I have this problem, and I want this outcome.".
Or: "I have this directory with these files: ..., and I want to do ... with each one of them."