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
Just join all lines together into a string:
open(F, $file) or die $!;
my $content = join("", <F>);
close F;
(It was previously suggested to use join "\n" but that will add extra newlines. Each line already has a newline at its end when it's read.)
There is a discussion of the various ways to read a file here.