Here I am this is me Theres nowhere else on earth Id rather be #### Here noun am verb Theres advb #### open DF, 'd.txt' or die $!; my %tagdict; while () { chomp; my ($word, $cat) = split; $tagdict{$word} = $cat; } while ( ($k,$v) = each %tagdict ) { #print "$k => $v\n"; } close DF; open CF, 'c.txt' or die $!; my %tagcorpus; while () { chomp; my @cwords = split; @tagcorpus{@cwords} = (1) x @cwords; } while ( ($k,$v) = each %tagcorpus ) { #print "$k => $v\n"; } close CF; open CF, '>c.txt' or die $!; foreach (keys %tagdict){ print values %tagdict if exists $tagcorpus{$_}; }