in reply to Regex exact pattern match problem!

Note that, in fact, moritz's improved version is essential—without it, your match has the potential to find your replaced text (since the s/// resets pos, so that the //g match starts all over again). For example, if you try your code (even suitably modified) on $toTranslate = 3 x 33332, then you'll get [[4]2], not [33332].

Note also that Perl goes out of its way to make sure that you can do lots of things that seem like they must be multi-step in a single statement. Thus, as moritz implicitly observed, it's probably better to write $tmpFound = length($1) (well, and use a better name) than $tmpFound = $1; $tmpFound = length($tmpFound).

UPDATE: On testing, moritz's version does the same thing. I think that you want something like

my $translated; while ( $toTranslate =~ /(.*?)((?:3{4})*)/g ) { $translated .= $1; $translated .= '[' . length($2) . ']' if $2; }

UPDATE 2: eye and AnomalousMonk pointed out a better, s///g-based solution: just omit the while.