4.9 Reading Multiple Lines From A File In One Read Operation
In previous sections, we have discussed multi-line strings that contain embedded newline characters. We conveniently built such strings using assignment and string concatenation. We have not seen yet how multiple lines can be read from a file in one read operation.
Perl provides a special variable called $/ that can be used to read multiple lines or paragraphs from a file. $/ is the so-called input record separator. The default value of the input record separator is \n. That is why when Perl reads from a file using a filehandle, it usually reads one line at a time. The newline character separates what Perl reads in one read operation from what it reads in the next.
By changing the value of the input record separator, Perl can be made to read several lines at a time. The value of $/ can be set to a single character or a string with multiple characters.