Using femtosecond pulse-shaping techniques, we are able to control several useful parameters of coherent anti-Stokes Raman spectroscopy (CARS). By shaping both the pump and the Stokes pulses with an appropriate spectral phase function, we eliminated the nonresonant CARS background. In addition, we designed pulses which selectively excite one of two neighboring Raman levels, even when both are well within the excitation spectrum. High-resolution CARS spectra were recorded in spite of the broad femtosecond pulse spectrum.