open(my $Raw_fh, ">", "Output_Raw.txt") or file_open_error_abort("Output_Raw.txt"); # This subroutine will print a file open error message, including the filename passed to it, and terminate the program after an acknowledgement from the user. sub file_open_error_abort { my $filename = $_[0]; say "Cannot open \"$filename\": $!."; print "---Press Enter to quit---"; my $pause = ; exit; } #### use utf8; use 5.022; use strict; say "BEGIN"; open(my $out_fh, ">", "permission_denied_output_file.txt") or die "Cannot open \"permission_denied_output_file.txt\": $!."; open(my $in_fh, "<", "no_such_input_file.txt") or die "Cannot open \"no_such_input_file.txt\": $!."; say "END"; END { use ExtUtils::MakeMaker qw(prompt); # placing this use statement here for convenient copy-paste of this END block code to other scripts. prompt('Please hit enter to exit.') if ($?); # stop and prompt for acknowledgement if program exits with a non-zero value. }