Well, the title says it all. Small example:
perl -e '$s="aaabbcc";$c=()=$s=~/a/g;print"$c\n$s\n"'
(m//g) outputs
3
aaabbcc
whereas perl -e '$s="aaabbcc";$c=()=$s=~s/a/x/g;print"$c\n$s\n"'
(s///g) outputs
1
xxxbbcc
I'd like to do both things at once without having to match first: substitute and know the number of substitutions. Obviously a s///g does not return the number of substitutions in scalar context--unlike m//g does with matches. Is this possible? If yes, how?
perlre, perlvar and perlop provided no help (or I just couldn't find it).