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


in reply to Jumping out of a partially read file

you can pretty much treat a file handle as a list of lines. Any old loop structure will do. I'm partial to foreach. The following code prints the first six lines of a file.
open(FILE,'<some_file.txt'); for((<FILE>)[0..5]){ print; }
Now lets say your special delimiter is a weird tie fighter thing like this :o:
We can slurp every line up to and including that like so.
open(FILE,'<some_file.txt') or die("cant open file: $!"); my $data; for(<FILE>){ if($_ !~ /:o:/){ $data .= $_; }else{ $data .= $_; last; } } close FILE;
Of course we should also check the first however many lines for the special character first to avoid slurping up the entire file if we dont find that character.