Why not show us what you are actually using rather than making us guess?

In general if you need to check if 'somethings' exist in a (large) 'something' else in Perl you tend to us a hash which is populated from the 'something' and keyed by potential 'somethings'. For example you could:

#!/usr/bin/perl use warnings; use strict; my %words; while (defined (my $line = <DATA>)) { ++$words{lc $_} for $line =~ /(\w+)/g; } printf "There are %d occurences of '%s'\n", $words{lc $_}, $_ for grep {exists $words{$_} && $words{$_} > 1} qw(text i); __DATA__ hi monks Happy new year to everyone i have any array with me say @arr which contains number of words(may c +ontain spaces) and i also have a text (in array) which contains a text of say + 1000 lines. i need to do

which prints:

There are 2 occurences of 'text' There are 3 occurences of 'i'
True laziness is hard work

In reply to Re: REGEX:getting the count of occerence by GrandFather
in thread REGEX:getting the count of occerence by ansh batra

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.