$ cat 980408.pl #!/usr/bin/perl -w use strict; while () { process_record() if /^START/; } sub process_record { my $line; while ($line = , $line !~ /^END/) { print "$line" } print "\n"; #a printout spacer for next record } __DATA__ XXXX YYYY START These are the first set of lines which are to be extracted END START New line And new Will be extracted? END XXX ZZZ YYY START These are the second set of lines which are to be extracted END aasds tteret tertetr $ ./980408.pl These are the first set of lines which are to be extracted New line And new Will be extracted? These are the second set of lines which are to be extracted $