while () { my ($test, $_) = /^(.+?):\s?([01]+)$/ or do { warn "Line $. is invalid: $_"; next }; print "$test $_: ", /^ (0+|1+) $/x ? 'PASS' : /^(1+0+|0+1+)$/x ? 'CLEAN' : 'FAIL', "\n"; } __DATA__ test 1: 000000 test 2: 111111 test 3: 000011111 test 4: 1111111000 test 5:10001001110000011 ..... so on