in reply to using a subroutine

Good start. Some suggestions:

  • Use 'my' when declaring your variables. Global variables are generally Not Good
  • Assuming those aren't the only two directories you'll ever want to process, consider passing in the directories on the command line, either directly through @ARGV, or via Getopt::Long (or Getopt::Std, if you're old-school)
  • Congrats on using use strict
  • in this program, there's really no reason to have the directories read by one subroutine and processed by another. A subroutine should generally be potentially useful to more than one caller. If it is only ever going to be called in one place, consider just moving it to that place (one exception to this "rule" is if you're breaking out significant chunks of code for increased clarity)