#!/usr/bin/perl -CSDA use utf8; use strict; use warnings; use Carp; my $whole_file = do { open my $f, "<", "mydata.txt" or croak "can't open mydata.txt: $!"; local $/; my $x = <$f>; $! and croak "can't read mydata.txt: $!"; close $f or croak "can't close mydata.txt: $!"; $x; }; print "data from file is: $whole_file\n";