#!/usr/bin/perl -w use strict; open WORDS, "< words" or die "cant' open words"; my (@words, @sentences); while () { chomp; push @words, [$_, qr/\b$_\b/]; } close WORDS; open SENTENCES, "< sentences" or die "cant' open sentences"; while () { my $printed = 0; for my $word (@words) { if (/$word->[1]/) { print $_ unless $printed++; print "\t", $word->[0]; } } print "\n" if $printed; } close SENTENCES; __END__ program's output: ------------------------------- I am the first first I always wanted to be the first first I never liked to be second second I second your request second Better second than third second third