use strict; my $count = 0; open (IN, "input.txt"); while () { if (/START/) { $count = 1; } elsif (/END/) { $count = 0; } elsif ($count) { print; } } close IN; #### These are the first set of lines which are to be extracted These are the second set of lines which are to be extracted #### elsif ($count && $_ !~ /^$/)