my $interesting_bit = 0; while(){ if(/--end foo--/){ $interesting_bit = 0; last; ## assuming only one interesting ## bit per file of course } if($interesting_bit == 1){ ## do my processing on the lines } if(/--start foo--/){ $interesting_bit = 1; # we've found the line which says # the next line needs to be processed } }