# this would try to re-use STDERR's file descriptor 2, # which dies with a "Bad file descriptor" error open STDERR, ">", \$variable or die $!; # closing STDERR first 'detaches' STDERR from file descriptor 2 # so it is then being re-opened to an internal file handle printf "fd=%d\n", fileno(STDERR); # 2 close STDERR; open STDERR, ">", \$variable or die $!; printf "fd=%d\n", fileno(STDERR); # -1 (not accessible from system()'s child process!)