@badwords = map { my $regex = join '\W*', (split //, $_); qr/$regex/i; } @badwords; foreach (@badwords) { $string =~ s/$_//gc; }