I am trying to write a script that goes through an entire folder of text files, matching a string pattern. What I want is the count of patterns matched in each file. In unix it could be done by `grep -c <pattern> *`. where the `-c` option returns you the count. Is there any way to get that count using perl regex? 

Please let me know.
['https://Stackoverflow.com/questions/5927010', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/743810/']
```
my $grep_count = grep (/PATTERN/, @array);

```

Or for a file:

```
perl -we "print scalar grep /PATTERN/, <>;" file.txt

```

<http://perldoc.perl.org/functions/grep.html>
Not that I know of, but just write it, when you open each file, use `while` to go through each of its lines, and use =~ against each line (with your pattern), if matched, then add 1 to your counter.