Differential perception and subsequent differential use of habitats can generate local adaptation, especially when natural selection cannot. However, this local adaptation is not maintained into future generations unless mating happens within the chosen habitats. We currently have no experimental data on whether differential perception of environments results in sexual isolation. We induced differential perception of environments by stimulating different olfactory neurons via light pulses (optogenetics) in two groups of fruit flies. These flies were released in a cage of which only one section received light pulses. One group of flies perceives this optogenetic stimulation as the smell of a harmful concentration of CO2 and was found to avoid the illuminated section. The other group perceives it as the smell of food-related compounds and was found to be attracted to the illuminated section. Due to this self-imposed spatial segregation, we subsequently observed a considerable degree of sexual isolation between the two groups of flies. In contrast, in two control treatments preventing differential perception of the environment, sexual isolation was virtually absent. Our results show that differential perception of the environment can easily and rapidly generate spatial segregation and sexual isolation among individuals that are ecologically different. This can maintain local adaptation, especially under conditions when natural selection cannot, which are increasingly common due to human-induced rapid environmental change.