my %good = map +($_ => 1), qw{ pre strong }; my $string = "xxx
xxxxxxxxx"; while ($string =~ m{<(\w+)>}g) { warn "bad word '$1'" unless $good{$1}; }