I have a small text file that I\'d like to read into a scalar variable exactly as it is in the file (preserving line separators and other whitespace).
The equivalent
From the Perl Cookbook:
my $filename = 'file.txt'; open( FILE, '<', $filename ) or die 'Could not open file: ' . $!; undef $/; my $whole_file = ;
I would localize the changes though:
my $whole_file = ''; { local $/; $whole_file = ; }