open my $fh, '<:raw', 'mydata.txt' or die $!; my $size = -s $fh; read($fh, my $data, $size) == $size or die $!; close $fh or die $!;