my $full_path = '/path/to/file'; #open my $fh, '>', $full_path or die "Unable to open [$full_path] to write!"; # see tinita below.. open my $fh, '>', $full_path or die "Unable to open [$full_path] to write! $!"; ... # this one or some variation.. close $fh or warning "unable to close [$full_path] $! fileno: ".(fileno $fh)." -e ".(-e $full_path); # more checks on directory? die if fileno $fh;