in reply to problem in outputting files to a new directory

Is it related to creating a directory using the string in $output, but trying to open a directory using the string in $dirname?

BTW, don't comment out strictures - ever!

Do use the three parameter version of open and use lexical file handles:

open my $inputFile1, '<', $input or die " Cannot open file $input: $!" +;

True laziness is hard work