use 5.010; # need (?PARNO) and possessive quantifier regex extensions use warnings; use strict; use autodie; use constant USAGE => <<"EOUSAGE"; usage: $0 filename target [ target ... ] where: filename required: name of file to be processed target required (1 or more): target block(s) to be deleted EOUSAGE MAIN: { die "no filename given \n", USAGE unless @ARGV >= 1; die "no target(s) given \n", USAGE unless @ARGV >= 2; my ($filename, @targets) = @ARGV; my $content = do { open my $fh, '<', $filename; local $/; <$fh>; }; print "before: >>$content<< \n\n"; # for debug my ($rx_target) = # build search regex map qr{ \b (?: $_) \b }xms, join '|', map quotemeta, reverse sort @targets ; print "search regex: $rx_target \n\n"; # for debug $content =~ s{ $rx_target \s+ [[:alpha:]]+ \s* ( \{ # begin capture group 1 (balanced curlies) (?: [^{}]*+ | (?1))* \} \s* ) # end capture group 1 } {}xmsg; print "after: >>$content<< \n\n"; # for debug exit; # successful exit from MAIN } # end MAIN block die "unexpected exit from MAIN"; # subroutines ###################################################### # none for now