# the original number of integers to test (will be one-upped) my $i = 1; # the input string to be tested (a number) my $foo = shift; # see if the input string is a two-digit number my $rc = ($foo =~ m{ \b (??{ ++$i; qr{\d{$i}}; }) \b }xmsg) ?'Y' :'N';