The argument I've always heard within the church against masturbation is taken from Genesis, regarding the story of Onan. His brother died, so according to the law of the time he was required to sleep with his brother's wife in order to impregnate her and continue his brother's family line. However, Onan didn't want to impregnate her so he "spilled his seed on the ground". God was angry about this and struck him down. That "spilled his seed on the ground" could be taken a couple of different ways -- one is that he "pulled out" before orgasm and spilled it that way. Another is that he simply masturbated instead of having sex with her. Either way, Onan was exhibiting rebellion against God by his actions, which is the point of the story.

My own belief is as Mark stated above -- it depends upon the heart and mind at the time of the act.