#!/usr/bin/perl $d = 1 ; $y = 0 ; while (<>) { # start $x = 0 ; $err = 0 ; if (/^BEGIN:VEVENT/) { if ($d) { print "$x: $_" ; } do { $x++ ; $line = <> ; if ($d) { print "$x: $line" ; } if ($line =~ /SUMMARY:Peski/) { $err = 1 ; if ($d) { print "*** MATCH ***\n" ; } } $seg .= $line ; } until ($line =~ /^END:VEVENT/) ; if ($err == 0) { $output .= $seg ; $g++ } else { push (@segs, $x); $y++; } next ; } $seg = "" ; $output .= $_ ; } print $output ; if ($d) { print "$g Events Kept $y Events Removed\n\n" ; for ($j = 0; $j < $y; $j++) { print " Seg$j: $segs[$j] Lines Removed\n" ; } }