in reply to Regex split string into n-length

Or possibly:

say join "-", split /\w{1,3}\K/ for @list;

With this list:

my @list = qw (12 123 1234 12345 123456 1234567 234 2345 23456);

this gives the following output:

12 123 123-4 123-45 123-456 123-456-7 234 234-5 234-56

Replies are listed 'Best First'.
Re^2: Regex split string into n-length
by AnomalousMonk (Archbishop) on Sep 10, 2013 at 12:08 UTC

    ++ Interesting use of  \K in split. Learned something today!