#! perl my @should_match = ( '123-456-789', '123.789.456', '963 456 741', ); my @should_not_match = ( '123-456.789', '123 789-456', '963.456 741', ); my $re = qr/\d{3}([ .-])\d{3}\1\d{3}/; for (@should_match) { if ($_ =~ $re) { print "ok\n"; } else { print "failed\n"; } } for (@should_not_match) { if ($_ =~ $re) { print "failed\n"; } else { print "ok\n"; } }