print "$_: ", m[^\w+(?:\.\w+){0,2}$] ? 'matched' : 'failed' for qw[ one one.two one.two.three one. one-two ];; one: matched one.two: matched one.two.three: matched one.: failed one-two: failed