my ($START, $END) = (11, 30); if ($string =~ /^\C{$START,$END}?($pattern)(?(?{ $+[0] < $END })|(?!))/) { # it's ok }