Its hard to say without a picture...but besides feces (which
shouldn't really ever be found hanging out of his vent) there are
several possibilities.
Male chameleons can get hemipene plugs. The are solid pieces of
semen or excretions that go along with semen. A vet can remove it
for you. Any of these that I have seen in pictures are about an
inch long and quite thin and shrivelled looking.
It could also be a prolapse. In males, there are hemipene
prolapses and intestinal prolapses.
Hemipene prolapses in veiled chameleons should be reddish
when they first happen...but if the hemipene remains outside
of the body too long it can turn dark (die/become necrotic).
If it dies, the hemipene can be amputated. If the chameleon is
taken to a vet before this happens, the vet can put the hemipene
back inside and put a purse-string stitch in the vent opening to
keep it in place for a while.
It could also be an intestinal prolapse which looks a bit like a
piece of sausage hanging outside his vent when it first happens.
Again...if the intestine remains outside of the body for too long
it will turn dark and die. If the chameleon is taken to a vet
before the intestinal prolapse turns dark, it can be put back...
just like the hemipene one can. If it dies...well...its not good.
With prolapses, its important to keep the "material" that
is hanging outside the vent moist. (Its not recommended to use
vaseline or an ointment that is intended to heal things. Its
always been recommended to me to use K-Y jelly or water.) The
chameleon should be taken to the vet's ASAP.
Aside from the above things, I don't know what it could be.
Can you post a picture of it?