#!/usr/bin/perl use strict; use warnings; my ($line, $cleanbook); my %badwords = (crud => "darn", shit => "shoot"); while ($line = ) { $line =~ s/["'.,!?:;\-()[\]{}|\\\/]/ /g; #replace all punctuation with a space my @sentence = split(/\W+/,$line); @sentence = map {$badwords{lc($_)}?$badwords{lc($_)}:$_} @sentence; $cleanbook .= join(' ', @sentence)."\n"; } print $cleanbook; __DATA__ "Crud," said Travis "Shit, this crud is shit!"