while() { s/[^\d]+//g; # remove non-digit characters # only digit characters remain m/(.{0,10})$/; # find as many as 10 characters, # starting at the right print $1,$/; # print the found digits } __DATA__ 800-1212 1-800-800-1212 1(800)800-1212 1 (800) 800-1212 1 800 800 1212