#!perl use strict; use warnings; while () { chomp($_); print "$_ okay\n" if /^(\d)((??{$+ + 1}))+$/; } __DATA__ 234 213 12345 #### 234 okay 12345 okay #### ((??{$+ + 1}))+ matches null string many times before HERE mark in regex m/^(\d)((??{$+ + 1}))+ << HERE $/ at ./test.pl line 8.