#!/usr/bin/perl
# w5.8.pl regex8.pl: Convert phone numbers. Use parens () to identify groups
# Prints second group as $2, third as $3

$_ = "(315)  268-6400";
#$_ = "(315)    2686400";			#DEBUG
#$_ = "3152686400";				#DEBUG

s/\(?(\d\d\d)\)?\s*(\d{3})[\s-]*(\d{4})/\1-\2-\3/;
print ("$2-$3");

#prints  268-6400

