in reply to Split with numbers

split allows to specify a regular expression. For your application something like split /(\d+)/ should work. You need to put the regex into parentheses as you want to keep the numbers.

Replies are listed 'Best First'.
Re^2: Split with numbers
by Laurent_R (Canon) on Nov 24, 2015 at 19:54 UTC
    This is a good idea in general, but won't work for the OP specific requirement: ABC23 will be split into ABC and 23, but split won't generate a third empty string.

    For example:

    $ perl -E ' say map { qq{"$_" }} split /(\d+)/ for qw[ AB23C ABC23 23 +BC ABC ]' "AB" "23" "C" "ABC" "23" "" "23" "BC" "ABC"

      Use of split can be stretched for the case of xyz268 ...

      split /([0-9]+)/ , $string , 3

      ... but still fails for the case of xyz.

        Yes, you're right, I did not think that specifying a limit to 3 would work properly in this case, and it does, but, as you said, it still won't work in the case of ABC:
        $ perl -E ' say map { qq{"$_"\t}} split /(\d+)/, $_, 3 for qw[ AB23C +ABC23 23BC ABC ]' "AB" "23" "C" "ABC" "23" "" "" "23" "BC" "ABC"