in reply to perlre inverse check for several patterns

Perhaps you just want to remove any patterns that are not allowed...

#!/usr/bin/perl use strict; # https://perlmonks.org/?node_id=11152608 use warnings; my @lines = split /^/, <<END; xxx<pre>xxx<www>xxx<strong>xxx xxx<pre>xxxxxx<strong>xxx xxx<pre>xxx<pr>xxx<strong>xxx xxx<pre>xxx<pree>xxx<strong>xxx xxx<pre>xxx<strong>xxx<strong>xxx xxx<pre>xxx<pre>xxx<strong>xxx END my %allowed = map { ( '<'.$_.'>' ) x 2 } qw( pre strong ); for ( @lines ) { my $clean = s[<\w+>][ $allowed{$&} // '' ]ger; print $clean; }

Outputs:

xxx<pre>xxxxxx<strong>xxx xxx<pre>xxxxxx<strong>xxx xxx<pre>xxxxxx<strong>xxx xxx<pre>xxxxxx<strong>xxx xxx<pre>xxx<strong>xxx<strong>xxx xxx<pre>xxx<pre>xxx<strong>xxx