$str = "000001"; $index = ( $str =~ /^(0*)/, length $1 ); print "$index\n";