in reply to read different loops

Maybe a simple state machine?

use strict; my $in_section = 0; foreach (<>) { $in_section=1, next if m{if\s+\(some\s+condition2\s+=\s+0\)}; $in_section=0, next if m{^\s*end\s+if;}; # next could be omitted...h +ere print if $in_section; } __END__ read this data 3; read data 4; read this data 6;
This one reads input from a list of files given by argument (@ARGV) when called as e.g. perl cond2reader.pl *.doc (or STDIN when no arguments were given). Alternatively, you can introduce an outer loop that opens all interesting files one after another (e.g. open my $fh, '<', $file or die "..."; foreach (<$fh>) { ... }
You might need to fine-tune the regular expressions a little bit.