We propose, based on results of first-principles calculations, that nanoporous graphene and h-BN might be efficiently produced from B–C–N layers as precursors. In our calculations, we find that the removal of the h-BN islands that naturally occur in BN-doped graphene, forming nanoporous graphene, requires less energy than if pristine graphene is used as a precursor. The same reduction ΔEf in pore formation energy is found for nanoporous h-BN obtained from graphene-doped BN as a precursor. ΔEf is found to increase linearly as a function of the number of B–C and N–C bonds at the island boundary, with the slope being nearly the same for either porous graphene or porous h-BN. This is explained by an analytical bond-energy model. In the case of porous graphene, we find that the pore formation energy would be further reduced by passivation by pyridinic and quaternary remnant nitrogen atoms at the pore edges, a mechanism that is found to be more effective than the passivation by hydrogen atoms. Both mechanisms for pore formation energy reduction should lead to a possibly efficient method for nanoporous graphene production.