#! /usr/bin/perl use warnings; use strict; if(scalar(@ARGV) != 3){ die "Usage: $0 inputfile.txt excludefile.txt outputfile.txt\n" ; } my $word = qr/(?) { while ($line =~ /($word('$word)?)/g) { undef $excluded{$1}; } } close $exclude; my %included; open my $input, '<', $ARGV[0] or die "Error opening input file: $!\n"; while (my $line = <$input>) { while ($line =~ /($word('$word)?)/g) { undef $included{$1} unless exists $excluded{$1}; } } close $input; open my $output, '>>', $ARGV[2] or die "Error opening output file: $!\n"; print $output join "\n", sort keys %included;