>perl -wMstrict -le "for my $string ('3' x 33332, @ARGV) { $string =~ s{ ( (?:3{4})+ ) }{ '[' . length($1) . ']' }xmsge; print $string; } " 3333333333223333322 333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333233333333322333333333233333333333333333333333333333333323333333322333333332333333333 [33332] [8]3322[4]322 [116]32[8]322[8]32[32]32[8]22[8]2[8]3