#libraries used are up above my @dirs=("C:/jobs/writebacks"); #array containing directories that are being searched foreach my $dir (@dirs) { #look at each directory my @files=read_dir($dir); # read directory $dir =~ /[^:]\/(.*)\/$/; my $end_direct = $1; chdir("$dir"); #change back to the directory just read foreach(@files) { #steps through each file in the contents if ( /^(\d{5})$/) { my $file= $1; #assigns regex to the file name $file = $file."/$end_direct"; DPSI::utils::mkdirR("C:\\FolderB\\$file"); DPSI::utils::nCopy ($_, "C:\\FolderB\\$file"); }#match bracket if statement }#inner for each }#outer