This article presents a size dependent mathematical model and an analytical solution methodology to accurately simulate and analyze the size dependent buckling behavior of piezoelectrically layered sandwich nanobeams with perforated core embedded in an elastic medium with flexoelectricity. The electric enthalpy energy function is expressed in terms of the electric and the flexoelectric effects. Regular squared cutouts perforation pattern is adopted for the perforated core. Closed forms for the equivalent geometrical parameters of perforated core are developed. The shear deformation effect is incroporated using the Timoshenko beam theory (TBT). To capture the nonlocality and the microstructure length scale effects, the nonlocal strain gradient elasticity theory is modified and adopted to include the electromechanical nonclassical effects. The Hamiltonian principle is utilized to derive the equilibrium equations. An analytical solution methodology is developed to derive closed forms for critical buckling loads. The developed solution procedure is implemented into a MATLAB software code. The accuracy of the developed procedure is verified by comparing obtained results with corresponding cases reported in the literature. Influences of different design variables on the electromechanical buckling behavior are explored through intensive parametric studies. Results obtained showed the significant effects of the flexoelectricity and the piezoelectric parameters on the size dependent buckling behavior of piezoelectric sandwich nanobeams with perforated core. Size dependent electromechanical as well as mechanical buckling behaviors could be controlled by adjusting these parameters. The developed procedure and the obtained numerical results are helpful in many technological and industrial applications as MEMS and NEMS.