$pattern =~ / ^ _* # 0 or more underscores to start ( (\d*|#*|\**)+ # Any combo of digits, #s, or *s (\[\d+\-\d\])? # Maybe a [x-y] ) (X*\.?\!?) # Zero or more Xs, and maybe a . or ! $ /gx; #### use strict; use warnings; use Test::More qw(no_plan); my $regex = qr{ ... stuff ... }x; # Tests like( '100', $regex, 'Valid numeric' ); like( '_100', $regex, 'Valid numeric with leading underscore' ); # etc. unlike( '', $regex, 'Invalid empty string' ); # etc.