Apical extracellular matrix (aECM) constitutes the interface between every tissue and the outside world. It is patterned into diverse tissue-specific structures through unknown mechanisms. Here, we show that a male-specific genetic switch in a single C. elegans glial cell patterns the aECM into a ~200 nm pore, allowing a male sensory neuron to access the environment. We find that this glial sex difference is controlled by factors shared with neurons (mab-3, lep-2, lep-5) as well as previously unidentified regulators whose effects may be glia-specific (nfya-1, bed-3, jmjd-3.1). The switch results in male-specific expression of a Hedgehog-related protein, GRL-18, that we discover localizes to transient nanoscale rings at sites of aECM pore formation. Blocking male-specific gene expression in glia prevents pore formation, whereas forcing male-specific expression induces an ectopic pore. Thus, a switch in gene expression in a single cell is necessary and sufficient to pattern aECM into a specific structure.