$string =~ s/(\w\w\w)/$1-/g;
UPDATE: As Ken pointed out correctly, this solution is wrong as it puts an additional - in a case like '123456'.
So, putting a negative lookahead to the pattern should do the trick:
$string =~ s/(\w\w\w)(?!$)/$1-/g;
McA
In reply to Re: Regex split string into n-length
by McA
in thread Regex split string into n-length
by hankcoder
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |