'234565432' =~ / (\d) (?{ $c = $1}) # Match the first number and initialize $c (?: (??{ ++$c }) # Same as the previous char + 1 )*/x; print $&;