if ($x =~ s/    #do a RegEx test and substitute 
  ^1?           #the match should start with zero or one 1, for USA
  \(?           #then zero or one open paren - before the area code
  ([2-9]\d{2})  #area code is three digits, first is 2..9
  \)?           #optional close paren after area code
  [ ]?          #optional space 
  (\d{3})       #three digits for the exchange
  [ -]?         #an optional space or dash
  (\d{4})       #the last four digits
  $             #must end the string
  /1($1) $2-$3/x #and replace what matched with 1(222) 123-4567
  ) {           #the /x allow for the comments and whitespace
    print "Valid number: $x\n";
}
else {
    print "unrecognized phone number\n";
}
