#! perl use strict; use warnings; my ($found, @lines); while () { if (my $flag = /START/ .. /END/) { $found = /def/ unless $found; push @lines, $_; if ($flag =~ /E0$/) { if ($found) { $found = 0; } else { print for @lines; } @lines = (); } } else { print; } } __DATA__ Source Data START abc def ghi END START xyz abc END #### 14:22 >perl 1646_SoPW.pl Source Data START xyz abc END 14:22 >