Read the grep documentation. grep returns a single item ($line) regardless of the number of matches found in the regex so @apples will contain either no elements, or a single element containing $line.
The regex on the other hand returns an element for each match so you get two elements in @apples for the first line where there are two matches.
In reply to Re: m// vs grep for counting occurances of a string
by GrandFather
in thread m// vs grep for counting occurances of a string
by Plankton
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |