in reply to Calculations in Regexp

The easiest solution: wrap your regular expression in a while loop:

#!/usr/bin/perl use strict; use warnings; $_ = 'aadsdfaasfga'; my $count; $count++ while /a/g; print "$count\n";

For a shorter and more clever solution, cast the match into list context and then count the matches:

#!/usr/bin/perl use strict; use warnings; $_ = 'aadsdfaasfga'; my $count =()= /a/g; print "$count\n";

Finally, to literally accomplish your goal, you can embed Perl code in the regex (see A bit of magic: executing Perl code in a regular expression). There are on-point examples in the link, but I'd recommend against it.