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 overlying aECM from a solid sheet to an ∼200nm pore, thus allowing a male sensory neuron to access the environment. Using cell-specific genetic sex reversal, we find that this switch reflects an inherent sex difference in the glial cell that is independent of the sex identity of the surrounding neurons. Through candidate and unbiased genetic screens, we find that this glial sex difference is controlled by factors shared with neurons (mab-3, lep-2, and lep-5) as well as previously unidentified regulators whose effects may be glia specific (nfya-1, bed-3, and jmjd-3.1). The switch results in male-specific glial expression of a secreted Hedgehog-related protein, GRL-18, that we discover localizes to transient nanoscale rings at sites where aECM pores will form. Using electron microscopy, we find that blocking male-specific gene expression in glia prevents pore formation, whereas forcing male-specific glial gene 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. Our results highlight that aECM is not a simple homogeneous meshwork, but instead is composed of discrete local features that reflect the identity of the underlying cells.