#!/perl/bin/perl use strict; use warnings; # The assumption is that the number will always be exactly ten digits my $s = "0123456789"; print $s, "\n"; $s =~ s/^(\d{3})(\d{3})(\d{4})$/($1)$2-$3/; print $s, "\n"; __OUTPUT__ 0123456789 (012)345-6789