$howmanytimes = @ary = $str =~ m/(stuff)/g; # or perhaps better as $howmanytimes = () = $str =~ m/stuff/g;