use strict; use warnings; my $toTranslate = q{3333333333773333377}; # 19 # .........1....1.... # ....5....0....5.... print qq{Sequences of 3s:-\n}; print qq{[@{ [ length $1 ] }]\n} while $toTranslate =~ m{(3+)}g; ( my $translated = $toTranslate ) =~ s{((?:3{4})+)}{ qq{[@{ [ length $1 ] }]} }eg; print qq{@{ [ q{-} x 50 ] }\n$translated\n@{ [ q{-} x 50 ] }\n}; 1 while $toTranslate =~ s{((?:3{4})+)}{ qq{[@{ [ length $1 ] }]} }eg; print qq{$toTranslate\n@{ [ q{=} x 50 ] }\n}; $toTranslate = q{3333333333333333333333333} # 25 . q{3333333333333333333333333} # 50 . q{3333333333333333333333333} # 75 . q{3333333333333333333333333} # 100 . q{3333333333333333373333333} # 125 . q{3377333333333733333333333} # 150 . q{3333333333333333333333733} # 175 . q{3333337733333333733333333} # 200 . q{3}; # 201 # .........1....1....2....2 # ....5....0....5....0....5 print qq{Sequences of 3s:-\n}; print qq{[@{ [ length $1 ] }]\n} while $toTranslate =~ m{(3+)}g; ( $translated = $toTranslate ) =~ s{((?:3{4})+)}{ qq{[@{ [ length $1 ] }]} }eg; print qq{@{ [ q{-} x 50 ] }\n$translated\n@{ [ q{-} x 50 ] }\n}; 1 while $toTranslate =~ s{((?:3{4})+)}{ qq{[@{ [ length $1 ] }]} }eg; print qq{$toTranslate\n@{ [ q{=} x 50 ] }\n}; #### Sequences of 3s:- [10] [5] -------------------------------------------------- [8]3377[4]377 -------------------------------------------------- [8]3377[4]377 ================================================== Sequences of 3s:- [117] [9] [9] [33] [8] [8] [9] -------------------------------------------------- [116]37[8]377[8]37[32]37[8]77[8]7[8]3 -------------------------------------------------- [116]37[8]377[8]37[32]37[8]77[8]7[8]3 ==================================================