http://www.perlmonks.org?node_id=1053231


in reply to Regex split string into n-length

You could also use unpack.

$ perl -E ' say for map { join q{-}, unpack q{(a3)*}, $_ } qw{ 12 123 1234 12345 123456 1234567 };' 12 123 123-4 123-45 123-456 123-456-7 $

I hope this is helpful.

Cheers,

JohnGG