m/ ^ # anchor to the beginning of the string -? # 0 or 1 dashes (for negative numbers I assume) \.? # 0 or 1 decimal points \d+ # 1 or more numbers (?:\.\d+)? # 0 or 1 decimal places followed by a number $ # anchor to the end of the string /x #### # some examples /^-?\.?\d+/ matches 123 or -123 or -.123 or .123 /^-?\.?\d+(?:\.\d_)?/ matches those and also 123.45 or -123.45 or -.123.45 (probably a bug!) or -123.23532 or .235235235235.235235235235235325