use strict; use warnings; my @badwords = qw/crud crap poo wanker/; while () { my $line = $_; my $plainline = $line; $plainline =~ s/["'.,!?:;\-()[\]{}|\\\/]/ /g; #replace all punctuation with a space my @sentence = split(/ /,$plainline); print join '|', @sentence,"\n"; foreach my $word (@sentence) { chomp($word); print "\tChecking *$word*\n"; my $whichword = 0; # to track which badword was found foreach my $badword (@badwords) { if (lc($word) eq $badword) { print "\t\tFound $badword\n"; #my $newword = replaceword($whichword); #get a cleaner word to replace the naughty word #$line =~ s/($word)/$newword/i; } $whichword++; } } #$cleanbook .= $line; } __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."