#!/usr/bin/perl -w use strict; my %bad_words = ( 'crud' => 'dirt', 'crap' => 'dung', 'poo' => 'dung', 'wanker' => 'fool' ); my $bad_re = join '|', keys %bad_words; while ( ) { s/\b($bad_re)\b/$bad_words{lc($1)}/ieg; print; } __DATA__ "Wanker!" said I. "Crap," says Travis. This is horse poo. Poo, I tell you! "Poo upon all the crud and crap the wanker could see." #### "fool!" said I. "dung," says Travis. This is horse dung. dung, I tell you! "dung upon all the dirt and dung the fool could see."