This paper presents a novel scheme for ultrafast all-optical pattern matching using the differential spin excitation in semiconductor multiple quantum wells (MQWs). In a demonstration of an all-optical pattern matching between two 100-Gb/s 16-bit optical packets, the contrast ratio of the photodiode (PD) output from the pattern matcher, between the pattern matched and the pattern-unmatched cases, was more than four for packets with a 2-dB power fluctuation. As an application of the pattern matcher to optical-packet-switched ring networks, bypass/drop self-routing is demonstrated for asynchronous 100-Gb/s 32-bit optical packets with 8-bit labels. In the experiment, a label of an incoming packet was compared to a local address (LA) given to a node in the optical domain. By changing the pattern of the LA packet instead of that of the incoming packet, the pattern matching was carried out for packets with various kinds of patterns. The contrast ratio of the PD output was more than six for all patterns.