It may be useful to restrict the scope of the file handle as well, since slurping is a one pass approach. That may be done with
my $string = do {
local $/;
open local(*FILEHANDLE), 'somefile.txt' or die $!;
<FILEHANDLE>
};
or, better if lexical filehandles are available,
my $string = do {
local $/;
open my $fh, 'somefile.txt' or die $!;
<$fh>
};
since the lexical handle is properly closed when it goes out of scope. Either way ensures no interference with other handles of the same name.
After Compline,
Zaxo