Scientists have transferred men's minds into a virtual woman's body in an experiment that could enlighten the prejudiced and shed light on how humans distinguish themselves from others.

In a study at Barcelona University, men donned a virtual reality (VR) headset that allowed them to see and hear the world as a female character. When they looked down they could even see their new body and clothes.

The "body-swapping" effect was so convincing that the men's sense of self was transferred into the virtual woman, causing them to react reflexively to events in the virtual world in which they were immersed.

Men who took part in the experiment reported feeling as though they occupied the woman's body and even gasped and flinched when she was slapped by another character in the virtual world.

"This work opens up another avenue for virtual reality, which is not just to transform your sense of place, but also your sense of self," said Mel Slater, a virtual reality researcher at the Catalan Institute of Research and Advanced Studies and University College London. "There isn't any other technology that allows you to look down and see another body that isn't yours and give you the illusion that it is," he said.

"If you can temporarily give people the illusion that their bodies are different, then the evidence suggests it also affects their behaviour and the way they think. They can have new experiences: a person who is thin can know what it's like to be fat. A man can have an experience of what it's like to be a woman."

In the study, 24 men took turns wearing a VR headset that immersed them in a virtual room. Some men saw the virtual environment through the eyes of a female character who was sitting down, while others had a viewpoint that was just to the side of her.

During the experiment, a second virtual female approached and appeared to rub the person's shoulder or arm. Researchers in the lab mimicked this sensation in the real world for some of the volunteers by rubbing their shoulder or arm, helping to reinforce their feeling of occupying the character's body.

Later in the study, the second character lashed out and slapped the face of the character the men were playing. "Their reaction was immediate," said Slater. "They would take in a quick breath and maybe move their head to one side. Some moved their whole bodies. The more people reported being in the girl's body, the stronger physical reaction they had."

Sensors on the men's bodies showed their heart rates fell sharply for a few seconds and then ramped up – a classic response to a perceived attack.

As expected, the body swapping effect was felt more keenly by men who saw their virtual world through the female character's eyes than those whose viewpoint was slightly to one side of her. In all cases, the feeling was temporary and lasted only as long as the study.

The study, which appears in the online science journal PLoS One, suggests that our minds have a very fluid picture of our bodies. The research is expected to shed light on the thorny neuroscientific puzzle of how our brain tells the difference between a part of our own body, and something else in the wider world.

The work might also improve rehabilitation for patients who have experienced strokes and other medical problems by immersing them in a world that helps them to use their bodies to the full again.