while ($str =~ m{ ( # capture to $1 . # any character (?: # this chunk: $ # either the end of the string | (??{ chr(1 + ord substr($&, -1)) }) # or the next character (ASCII-wise) after # the one we just matched )+ # one or more times ) # end capture }xgs) { print "run: <$1>\n"; }