use Regexp::Common qw(profanity); my %bad2good = (...); while(<>) { s/($RE{profanity})/$bad2good{lc $1}/gi; print; }