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


in reply to Re: How to delete contents between two strings.
in thread How to delete conetents between two strings.

Uuii, the Range Operator in scalar/boolean mode. I just learned this year about it. Very nice solution, toolic.

In case the Anonymous Monk, or someone else with a similar homework ;-), needs the ** lines included, the feature that '..' in scalar mode returns an increment for every true evaluation and adds 'E0' on the last, can be used:

#!/usr/bin/perl use strict; use warnings; while (<DATA>) { my $i = (/\*\*Temp/ .. /\*\*End/); print unless ($i && $i > 1 && substr($i, -2) ne 'E0'); } __DATA__ first second **Temp** fdvfd fgd dfgd dfgd **End Temp ** this is test dffdgd this is test dffdgd

prints:

first second **Temp** **End Temp ** this is test dffdgd this is test dffdgd