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

omegaweaponZ has asked for the wisdom of the Perl Monks concerning the following question:

Hi monks,

I'm still a newbie when it comes to regular expressions. I'm OK with matching and replacing strings, but I'm trying to use re's to take a single string and add spaces to it. See example below:

$oldstring = '123456789'

-- regular expression function --

$newstring = '123 456-789'

Any ideas? I'm assuming it's based on counting characters based on .. as those characters will constantly change, but the order in which I need them to add a space or - will not