foreach my $string (@string){ if(($string =~ m/1(?=[^1])/g)||($string =~ m/^0+$/g)){ print "not a match\n"; } else{print $string, "\n";} }