http://qs321.pair.com?node_id=1202989

chengchl has asked for the wisdom of the Perl Monks concerning the following question:

Hi Monks,

I have seen the post here about "Getting lines in a file between two patterns" (http://www.perlmonks.org/?node_id=979946)

I was curious that what if I need to extract only the second block of lines that meet the pattern?

Is there something that we can do via (/START/ .. /END) pattern matching? Many thanks

That is:

I have a text file -

abc efg ... START lines not to be extracted END START lines to be extracted END START lines not to be extracted END ...

I think I find a way. Thanks guys

my $count = 0; 11 while (<$fh_r>) { 12 if (/START/ .. /END/) { 13 $count++ if /START/; 14 print if ($count == 2); 15 } 16 }

--- Updated on Nov. 10, 15pm PST Thank you so much guys. I read through all your answers and appreciate your help. Thank you all and have a nice day.