while ( ) { if ( /--- start foo ---/ ) { # we're about to start processing while ( ) { last if /--- end foo ---/; # here's a line of stuff to process } # we're done with this block } }