use strict; use warnings; open(my $file1, '<', $ARGV[0]) or die "Can't open $ARGV[0]: $!\n"; my @substitutions = <$file1>; close($file1); chomp(@substitutions); open(my $file2, '<', $ARGV[1]) or die "Can't open $ARGV[1]: $!\n"; while(my $line = <$file2>) { for my $replace (@substitutions) { next unless $replace; # skip blanks $line =~ s/\Q$replace\E/foo/g; } print $line; } close($file2);