High Mach number, collisionless perpendicular shocks are known to accelerate electrons to strongly relativistic energies by diffusive shock acceleration. This presupposes the existence of mildly relativistic electrons, whose preacceleration mechanism from lower ambient energies (the injection problem) remains an open question. Here a particle in cell simulation is used to investigate the preacceleration mechanism. Depending on the parameters of the upstream plasma and the shock velocity, the growth rate of instabilities in the foot of the shock can be significant, leading to the existence of nonlinear modes and the formation of electron phase space holes. It is found that these are associated with electron preacceleration, which can be divided into three phases. In the initial phase electrons are accelerated in the shock foot by the surfatron mechanism, which involves particle trapping in nonlinear wave modes. This mechanism is strongly linked to the existence of solitary electron phase space holes. The second phase is characterized by fluctuations in the magnetic field strength together with μ-conserving motion of the electrons. Finally, in the third phase the magnetic moment μ is no longer conserved, perhaps due to turbulent scattering processes. Energies up to Lorentz factors of 6 are achieved, for simulations in which the inflow kinetic energy of upstream electrons is 3.5 keV.