We propose an ultrahigh-efficiency and broadband all-optical switching scheme based on coherent perfect absorption (CPA) in linear and nonlinear excitation regimes in a cavity quantum electrodynamics (CQED) system. Two separate atomic transitions are excited simultaneously by two signal fields coupled from two ends of an optical cavity under the collective strong coupling condition. Three polariton eigenstates are produced which can be tuned freely by varying system parameters. The output field intensities of multiple channels are zero when the CPA criterion is satisfied. However, destructive quantum interference can be induced by a free-space weak control laser when it is tuned to be resonant to the polariton state. As a consequence, the CQED system acts as a coherent perfect light absorber/transmitter as the control field is turned on/off the polariton resonances. In particular, the proposed scheme may be used to realize broadband multi-throw all-optical switching in the nonlinear excitation regime. The proposed scheme is useful for constructing all-optical routing, all-optical communication networks and various all-optical logic elements.