use strict; my $swearwords= join '|', qw/bad worse ugly/; my $text='This is a bad sentence with some ugly and worse words'; $text=~s/$swearwords/****/g ; print $text;