your code is a little hard to understand!!!
please let me know if this solves your problem
#! /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=<FILE>; 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);
file1.txt
ansh batra perl postgres apache monks
file2.txt
ansh batra is in perl monks apache postgres
file3.txt
website monks perl website ansh ansh website
output.txt
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
thanks!!!
ansh batra

In reply to Re: Searching through a word file using an array element by ansh batra
in thread Searching through a word file using an array element by coldwish

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.