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


in reply to File Reading and Closing confusion

Another difference not mentioned by the estemed monks above:
while (<FH>) {...}
assigns a line to $_ on each iteration of the loop, as mentioned, however outside a loop it does not. Just plain
<FH>;
does read a line from the file, but does not assign it to $_. So far as I know it is not stored. The assignment to $_ is magic that only occurs inside the condition of a while loop. $line = <FH>; works as expected - the line which has been read is assigned to $line.

By the way, if you use sysread the you should open with sysopen, but there is also read which is used after our old friend open. With read you can specify how many characters to read, which can also be done with $/ (although I find read easier to um, read).