#! perl use strict; use warnings; my $in_file = 'temp1.txt'; # this must exist my $outfile = 'temp2.txt'; my $arrayref = []; open(my $in, '<', $in_file) or die "Cannot open file '$in_file' for reading: $!"; open(my $out, '>', $outfile) or die "Cannot open file '$outfile' for writing: $!"; can_write( $in_file, $in); can_write( $outfile, $out); can_write('$arrayref', $arrayref); close($in) or die "Cannot close file '$in_file': $!"; close($out) or die "Cannot close file '$outfile': $!"; sub can_write { my ($name, $fh) = @_; my $result = eval { no warnings; print $fh '' }; printf "$name %s write\n", ($result ? 'can' : 'cannot'); } __END__ temp1.txt cannot write temp2.txt can write $arrayref cannot write