print "\nEnter your words (separated by spaces): >> "; chomp(my $line = ); my @words = split /\s+/, $line; foreach $word(@words) { if() { #Set a condition to match more than one word, i.e to match combination of multiple words } else { open(FH, $kwords)&& open(MN, ">>$sResult") || die ("Cannot open [$kwords,$sResult], $!\n"); print RESULT "==============================\n"; print RESULT "\t ", uc($word),"\n"; print RESULT "==============================\n"; { local $/=undef; print RESULT grep { $_ =~ /$word/i } =~ m!(.*?)!gs; } print MN "\n"; close MN; close FH; } __DATA__ c:\data\cat.xml dog, cat, fish, bird c:\data\cow.xml dog, cat, fish, bird, cow, goat c:\data\snake.xml dog, cat, fish, bird, snake, orange #### c:\data\fat.xml snail, cat, eagle, fly, chicken, elephant