Houdini would put a length of string and a handful of needles in his mouth and swallow them. A moment later, he would regurgitate the string and all the needles would be threaded onto it.
Although the string is put into the mouth first, it is retained in the cheek. When the needles are put into the mouth, they are held as a neat packet with all of their holes aligned. It is then a simple matter of threading one end of the string through the aligned holes with the tongue (using a swallowing motion to create helpful suction). With this complete, the needles are threaded and can be removed for inspection.
Houdini performed a variety of variations of this trick, including one in which he swallowed a ball of yarn and, twenty minutes later, coughed up a sweater.
Trivia: In the movie Internal Affairs, Richard Gere's character Dennis Peck performs this trick with the help of a trained hamster that is swallowed beforehand. Misremembrences of this scene have led to some rather unfortunate rumors about Mr. Gere's use of gerbils.