@files = readdir DH; open STDOUT, '> '.$Location2.'\ProcessedFilesInDir.txt'; foreach $file (@files) { $file1 = "tool.exe [- options]"; system ($file1) == 0 or die "system @args failed: $?"; if ($? == -1) { print "failed to execute: $!\n"; } elsif ($? & 127) { printf "child died with signal %d, %s coredump\n", ($? & 127), ($? & 128) ? 'with' : 'without'; } else { printf "child exited with value %d\n", $? >> 8; } } close STDOUT;