use warnings FATAL => 'all' ; use strict; use Test::More # tests => ?? + 1 # Test::NoWarnings add 1 test 'no_plan' ; use Test::NoWarnings; my @matches = ( '123 456 789', qw(123.456.789 123-456-789 123-456789 123456-789 123-456789123456 123456789123-456 123-4-5-6-7-8-9-1-2-3-456 123-4-5-6-789 1234-56789 123456789-123456 123456789 123456789123456), qw(x123-456-789x x123456-789x x123456789x), qw(x123-456789123-456x x123456-789123456x x123456789123456x), ); my @no_matches = ( # none shall pass! '', qw(a abcdefgh abcdefghi 12345678 1234567891234567 123-45-678 123-4567891234-567 -123456789 123456789- 1-23456789 12345678-9 1-2345678-9 12-3456789 1234567-89 12-34567-89 -1234567891234567 1234567891234567- 1-234567891234567 123456789123456-7 12345678-91234567 12-34567891234567 12345678912345-67 ), ); MATCHER: for my $matcher (qw(m1)) { note "matching with $matcher()"; *match = do { no strict 'refs'; *$matcher; }; note "ALL the following should match"; for my $n (@matches) { my ($m, $d) = match($n); ok $m, qq{match: '$n' (diff $d)}; } note "NONE of the following should match"; for my $n (@no_matches) { my ($m, $d) = match($n); ok ! $m, qq{NO match: '$n' (diff $d)}; } } # end for MATCHER sub m1 { my ($string, ) = @_; my $diff = qr{ [-. ] }xms; # differentiator chars my $d_min = qr{ \d{3,} }xms; # minimum group of digits local our ($digits, $diffs); use re 'eval'; my $ndn = qr{ (? 10 || $digits > 15 || $digits < 9 }) (*FAIL)) }xms; my $match = $string =~ $ndn; my $diff_seq = defined($1) ? qq{'$1'} : 'undef'; return $match, $diff_seq; } # end sub m1()