#!/usr/bin/perl use strict; use warnings; while () { chomp; print m/\d(?:(?:\d| (?!\d))){19}/ ? "$_ matches\n" : "$_ does not match\n"; } __DATA__ "01234567890123456789" "123" "123 123 " "123c " " " "11232424525252423 "