/ ^(0|1)$ # simple cases of 1 or 0, with zero 01|10 | ^1(0|1)*1$ # 1 .. anything .. 1 | ^0(0|1)*0$ # 0 .. anything .. 0 /x #### my @tests = qw( 0 1 01 10 00 11 000 111 001 011 101 010 100 110 1001 1101 0101 1010 ); foreach (@tests) { print "$_ "; if (/^(0|1)$|^1(0|1)*1$|^0(0|1)*0$/) { print "passed\n"; } else { print "failed\n"; } }