... { # create the file, must be world-writable my $temp = MyApp::Local->umask(0); my $fh; sysopen($fh, $path, O_WRONLY | O_CREAT | O_EXCL, 0666) or die "$path: $!\n"; close $fh; # umask restored when $temp goes out of scope, even by dying } ...