#!/usr/bin/perl -w use strict; open WORDS, "< words" or die "cant' open words"; my (@words, @sentences); while () { chomp; push @words, $_; } close WORDS; open SENTENCES, "< sentences" or die "cant' open sentences"; push @sentences, $_ while ; close SENTENCES; for my $word (@words) { my @found = grep /\b$word\b/, @sentences; if (@found) { print $word, ": \n\t", join "\t", @found; } } __END__ contents of file "words" ------------------------------- first second third fourth ------------------------------- contents of file "sentences" ------------------------------- I am the first I always wanted to be the first I never liked to be second I second your request I will never appear in the output Better second than third ------------------------------- program's output ------------------------------- first: I am the first I always wanted to be the first second: I never liked to be second I second your request Better second than third third: Better second than third