In Perl you would write something like :
s/(\d{3})(\d{3})(\d{4})/\1 \2 \3/
s is the substitute operator
the first bit between / and / is the pattern to match (and () groups the matches)
the second bit between the / and / is what to replace it with, and \1 etc refers to the first () group that matched, etc.