#! /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) { next if length $1 < 4; undef $included{$1} unless exists $excluded{$1}; } } close $input; %excluded = (); open my $output, '<', $ARGV[2] or die "Error opening dictionary file: $!\n"; while (my $line = <$output>) { while ($line =~ /($word('$word)?)/g) { undef $included{$1}; } } close $output; open $output, '>', $ARGV[2] or die "Error opening output file: $!\n"; print $output join "\n", sort keys %included;