perl -wle '$_ = "345678"; print ":" . ( /./g )[ 1 ]' # output: ':4' (second match for e.g. index 1)