in reply to Return the contents of a file

You can also redefine the input record separator $/ to a null string:
local $/; my $scalar = <FH>;
That obviates the need for a while loop. Normally, $/ is set to a newline. That's why the magic <FILEHANDLE> reads one line at a time. Using a local $/ will change that to whatever separator you want. Specify none, slurp the whole thing. That could make your first example even more compact.