>perl -wMstrict -le "my @strings = ( 'foo bar \"stuff\" *&! baz', 'fee P fie Q foe R fum S', 'hee W hie X hoe Y hum Z', ); ;; my $ar_keep_tag_content = [ 1, tag_group_regex(qw(b cd)) ]; my $ar_kill_tag_content = [ 0, tag_group_regex(qw(efg) ) ]; ;; for my $s (@strings) { print qq{'$s'}; for my $pass ($ar_keep_tag_content, $ar_kill_tag_content) { my ($keep_content, $tag) = @$pass; $s =~ s{ < \s* ($tag) \s* > (.*?) } { $keep_content ? $2 : '' }xmsge; print qq{'$s'}; } print ''; } ;; sub tag_group_regex { my $alternation = join '|', @_; return qr{ (?i) $alternation }xms; } " 'foo bar "stuff" *&! baz' 'foo bar "stuff" *&! baz' 'foo "stuff" *&! baz' 'fee P fie Q foe R fum S' 'fee P fie Q foe R fum S' 'fee P fie Q R S' 'hee W hie X hoe Y hum Z' 'hee W hie X hoe Y hum Z' 'hee W hie X Y Z'