Masturbation is a problem if your child feels he always needs to do it and/or it begins to interfere with the other activities in his life (for example, school or playing with friends). If an older child is still openly masturbating, it may provide a clue to a larger problem of inappropriate social development.
The issue of "playing doctor" is a tricky one. In many cases, children are simply acting out images to which they have been exposed. Exploration of the sexual organs with other children is part of normal sexual development. However, it is important to set limits on this type of behavior. Laying ground rules like "you may not touch other people's private parts," or "you may not show your private parts to other children" is an appropriate step for parents to take. Furthermore, this sort of discussion is an opportunity to remind your son again that he can always ask you questions about his genitals if he is curious. Keeping lines of communication open now will set a good precedent for the future when confronting issues of sexuality as your child enters puberty and matures.
If you feel that your efforts are unsuccessful, and the public masturbation or an unacceptable type of playing doctor continues, then it would be appropriate to discuss this with your child's pediatrician.