A PEM or Proton Exchange Membrane is quite simply a piece of plastic with an acid group. Now that all sounds quite scientific, so we will try to dig a bit down.
A proton is nothing less of a hydrogen atom stripped of its electron as shown in figure 1:

Figure 1: Half reaction of hydrogen
These protons behave a bit like electrons (or electricity for convenience purpose) and can be transported. Whereas copper or aluminum are great conductors for electricity, protons can’t be transported through these media. Protons are conducted by acid groups, such as: sulfuric acid, phosphoric acid and perchloric acid.
In their original form, these acids are best known as liquids which makes separating 2 gasses challenging. Preferbly these acids are solid and do not allow for crossover so that gasses can mix. In order to encapsulate these acids, they have been synthesized to a polymer to create something similar of a plastic. Some of these polymers with an acid group attached to them are specific for use in fuel cells, electrolyzers, electrochemical hydrogen compression and purification are called Proton Conducting Membranes (PEM). Most known is Nafion(tm), which is a PFSA type of membrane (Poly Fluor Sulfonic Acid). The fluorine molecules within this polymer ensure chemical stability and the sulfonic acid ensures the proton conductivity

Figure 2: Chemical structure of Nafion (source: https://www.mdpi.com/2079-6412/8/5/190)
Proton on the move
Now how does a proton travel through the membrane? There are 3 known mechanisms described within the scientific literature.

Figure 3: 3 known proton conducting mechanisms (source: https://www.researchgate.net/figure/The-a-vehicle-mechanism-b-Grotthuss-mechanism-and-c-surface-mechanism-in-the_fig20_370018554)
Vehicle mechanism:
The vehicle mechanism is based on the idea that the proton is being transferred from one water molecule to the other within the polymer
Grotthus mechanism:
Named after the German scientist Theodor von Grotthuss describing the transport of protons through cooperation of neighbouring watermolecules (source: https://www.sciencedirect.com/topics/engineering/grotthuss-mechanism)
Surface mechanism:
The surface mechanism theory describes proton conductivity through the water molecules attached to the sulfonic acid groups on the membrane. There protons permeate through the membrane by hopping from one sulfonic acid group to the next until the proton is oxidized into a stable molecule again.
And there you have it, a very brief explanation on how PEM membranes work.