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
I don't have enough reputation to comment, so I apologize for making this another post.
@ Harold Bamford: $/ should not be an obscure variable to a Perl programmer. A beginner may not know it, but he or she should learn it. The join method is a poor choice for the reasons stated in the article linked by hackingwords above. Here's the relevant quotation from the article:
That needlessly splits the input file into lines (join provides a list context to ) and then joins up those lines again. The original coder of this idiom obviously never read perlvar and learned how to use $/ to allow scalar slurping.