Since while evaluates the condition in scalar context and the line input operator (<>) returns the next line of input (or undef on end-of-file) in scalar context, that code processes file line by line.
On the other hand, when <> is evaluated in list context, it returns a list of all lines (they all go the memory!) from file.
while (<$fh>) { # Read line by line; generally preferred way (especi
+ally for large files)
print "The line is: $_";
}
foreach (<$fh>) { # Read all lines at once
print "The line is: $_";
}