http://www.perlmonks.org?node_id=20235

File::Slurp allows you read a filehandle into a scalar. However there is another way to do this without having to load an extra module at runtime. The select statement changes $/ (the input record separator) to a null character instead of a \n. And there you go..
#!/usr/bin/perl my $file="foobar"; open (FILE, $file) or die "Can't open $file: $!\n"; select((select(FILE), $/ = undef)[0]); my $contents = <FILE>; close (FILE);