use Fatal qw(:void open); if(open my $log, '>', $log_file) { print $log $message; } else { print STDERR $message; # Now it is reachable }