http://www.perlmonks.org?node_id=991093


in reply to how to to find the "/" in a string

Here is a start. The regular expression gets the size of the array returned by the regular expression, which uses () to enclose the text to be searched for and /g to find all the occurences.

use feature ":5.14"; use warnings FATAL => qw(all); use strict; my $h = "aaa bbb ccc aaa aaa"; say scalar (() = $h=~m(aaa)g);

Produces

3