$float =~ m/ \A # beggining of string \d{0,$max_lhs} # 0 to $max_lhs digits (?= # non capturing grouping \. # decimal point \d{1,$max_rhs} # 1 to $max_rhs digits )? # grouping is optional \z # end of string /xms;