http://qs321.pair.com?node_id=673967


in reply to Grep reutrn the occurance of a pattern

To get the number of matches you evaluate grep in scalar context. Here:

#!/usr/bin/perl use strict; use warnings; my @items = qw/yes no no no yes yes no no/; my $number_of_matches = grep(/yes/,@items); print "$number_of_matches\n";

Prints 3.

Update: Noticed that I left out @items, and I see I am not alone in my confusion about exactly what it was the OP wanted.