The only way to be 100% safe against getting pregnant is to not have any contact between genitals - no exchange of seminal fluid and vaginal secretions. People have had a pregnancy without ever having had sexual intercourse.
There are many ways of showing loving and caring besides having sex. These ways include talking as well as touching.
Masturbation is touching your genitals yourself or having others touch them in a way that feels good and often ends in orgasm (ejaculation).