use Regexp::Assemble; my $ra = Regexp::Assemble->new; $ra->add(@words); my $re = $ra->re; s/$re//gsi; # this will replace # foreach (@words) { ... s/// ... } # and do the word deletion in one go