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


in reply to Reading entire file.

Update: Oops, thank you cLive--I misread the $that = 0; as another $that = 1 and therefore saw it as just checking and printing single lines.

As for your problem with stopping, I'm not seeing any reason why this section wouldn't work (assuming $foo and $bar are what you want them to be)

Ps. You can print $. instead of keeping a counter.