use strict; # Please do this! use warnings; # And this! # First, read from the filehandle to grab the list # of banned words. map the banned words into hash-keys. my %banned = map { chomp $_; $_=> undef } split /\s+/, ; my $infile = "textfile.txt"; my $tmpfile = "outfile.tmp"; open my $in, "<$infile" or die "Cannot open $infile.\n$!"; open my $out, ">$tmpfile" or die "Cannot open temp output file.\n$!"; while ( my $inline = <$in> ) { chomp $inline; my $printline = ""; foreach my $word ( split /\s+/, $inline ) { next if exists $banned{ lc $word }; $printline .= $word; } print $out "$printline\n"; } close $out; close $in; rename $tmpfile, $infile; __DATA__ a at be for and to of in the as i it are is am on an you me b c d e f g h j k l m n o p q r s t u v w x y z 0 1 2 3 4 5 6 7 8 9 10