$bad_words = array('ugly', 'anotherugly'); $good_words = array('ug**','anot******y'); $txt = 'ugly anotherugly'; $txt str_replace($bad_words, $good_words, $txt); #### #!/usr/bin/perl use warnings; use strict; my %words = ( ugly => 'ug**', anotherugly => 'anot*******', ); my $txt = "ugly anotherugly"; $txt =~ s/$_/$words{$_}/g foreach %words; print $txt;