my $data = do { local $/, }; #### open my $fh, '<', $filename or die $!; while ( <$fh> ) { ... # process one line at a time }