perl -wle '$_ = "345678"; print ":" . @{[ /./g ]}' # output: ':6' (6 - number of matches => number of array elements)