use strict; my @swearwords = qw/bad worse ugly/; my $text='This is a bad sentence with some ugly and worse words'; $text=~s/$_/****/ foreach @swearwords; print $text; #### 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;