I could think of this very simple code, it gives you an idea about creating a list, that list is saved in @array and then for each element in the array there happens a match check that increments the count when true, you have each element checked and the checking goes on till all the array elements have been checked for the pattern /\bsaravanan\b/ ...
!/usr/local/bin/perl $string="a student name is sa\nravanan. saravanan is studying 3rd stan +dard.i am go with sara\nvanan"; $count = 0; $string =~s/\n//g; #removing \n print "$string\n"; @array = split(" ", $string); #making the string into individual +list elements foreach $element(@array){ if($element=~/\bsaravanan\b/){ $count++; } } print "found: $count matches.\n";
Excellence is an Endeavor of Persistence. Chance Favors a Prepared Mind

In reply to Re^3: reading file by biohisham
in thread reading file by saranperl

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.