use strict; use warnings; my $fn; print "\nType filename.\n"; chomp ($fn = ); print "\nOpening file named $fn\n"; if (open my $fh, '<', $fn) { print "Successfully opened file '$fn'\n"; close $fh; } else { print "Error opening file '$fn': $!\n"; }