http://www.perlmonks.org?node_id=976612


in reply to Re^4: text matching
in thread text matching

Here is the program using a different approach with the range operator.
#!/usr/bin/perl use strict; use warnings; while (<DATA>) { if ((my $first = /^\s*#if/) .. (my $last = /^\s*#endif/)) { #print if $first || $last; print unless /^\s*reports?/; } else { print; } }

Its a neat use of the range, ( .. ), operator.

Chris

Update: changed the first print line to more accurately perform what you needed.