#! /usr/bin/perl -w use strict; my @arr=('perl','monks','website'); our @files=('file1.txt','file2.txt','file3.txt'); open(LOG,">","output.txt"); my $file; foreach $file(@files) { open(FILE,"<",$file); my @lines=; close(FILE); my $count=0; my $line; foreach $line(@lines) { $count++; if($line =~ /.*$arr[0]/) { print LOG "$arr[0] found in $file at line number $count\n"; } if($line =~ /.*$arr[1]/) { print LOG "$arr[1] found in $file at line number $count\n"; } if($line =~ /.*$arr[2]/) { print LOG "$arr[2] found in $file at line number $count\n"; } } } close(LOG); #### ansh batra perl postgres apache monks #### ansh batra is in perl monks apache postgres #### website monks perl website ansh ansh website #### perl found in file1.txt at line number 3 monks found in file1.txt at line number 6 perl found in file2.txt at line number 1 monks found in file2.txt at line number 1 website found in file3.txt at line number 1 perl found in file3.txt at line number 2 monks found in file3.txt at line number 2 website found in file3.txt at line number 2 website found in file3.txt at line number 5