The evolutionary paths taken by each sex within a given species sometimes diverge, resulting in behavioral differences that promote specific fitness outcomes for each sex. Given their distinct needs, the mechanism by which each sex learns from a shared experience is still an open question. We reveal a novel sexual dimorphism in learning: C. elegans males do not learn to avoid the pathogenic bacteria PA14 as efficiently and rapidly as hermaphrodites, even though their innate immunity recognizes the pathogen in a similar manner. Notably, we observe sexually dimorphic neuronal activity following pathogen exposure: hermaphrodites generate robust representations while males, in line with their behavior, exhibit contrasting representations, suggesting that a mechanism that modulates incoming sensory cues is at play. Transcriptomic and behavioral analysis revealed that the neuropeptide receptor npr-5, an ortholog of the mammalian NPY receptor, regulates male learning by modulating neuronal activity. Furthermore, we show the dependency of the males decision-making phenotype on their sexual status and demonstrate the pivotal role of npr-5 in this regulation as a sensory gatekeeper. Thus, collectively, we portray sex-specific plasticity in behavior toward a shared experience by modulating learning to fulfill the evolutionary needs.