use strict; use warnings; while () { chomp; print m/(\d{1,20})(??{' ' x (20 - length($1))})/ ? "match\n" : "not match\n"; } __DATA__ " 123451234512345" " 123451234512345 " "123451234512345 " "1234512345 " "123 451 2345 " " "