During this stage of metamorphosis, which usually takes from two weeks to several months, the larval tissues completely break down and reorganize. When the butterfly is fully formed, the pupal case splits and the butterfly emerges. The butterfly first expels its meconium, metabolic waste products that have accumulated during the pupal stage. The primary function of the male butterfly is to find a female. The male butterfly uses vision to locate a female of his own species, then lures her with chemicals called pheromones, produced by his scent glands.
Some species also perform elaborate courtship flights.
Once the female has mated, she must lay her fertilized eggs on the appropriate larval host plant.