in reply to Re: Searching no. of times the pattern occurs in the data
in thread Searching no. of times the pattern occurs in the data

If you put the pattern in a lookahead and replace with nothing, you'll save CPU cycles:
my $count = s/(?=$pat)//gsi;

If there are no capturing parentheses in the expression, you can simply use the match operator instead.

my $count = () = /$pat/gsi;

Caution: Contents may have been coded under pressure.