perl -wle '$_ = "345678"; print ":" . ( () = /./g )' # output: ':6' (6 - number of matches; special behaviour)