open STDERR, ">> error.txt" or die "$!"; system("identify -verbose $directory\\$DIR[$a] >> c:\\dump.txt") or print STDERR "Error: Error message here";