Behavioral studies of Caenorhabditis elegans traditionally are done on the smooth surface of agar plates, but the natural habitat of C. elegans and other nematodes is the soil, a complex and structured environment. In order to investigate how worms move in complex environments, we have developed a technique to study C. elegans locomotion in structures fabricated from agar. A microfluidic structure containing an array of posts was designed and the movement of worms in these structures was studied by video microscopy. We discovered that worms are capable of a novel mode of locomotion - a combination of the fast oscillatory movements of swimming with the efficiency of crawling. When the wavelength of the worms matched the spatial scale of the post array, the microstructure directed and increased the swimming speed C. elegans ten-fold. However, we found that the swimming speed of mutants defective in mechanosensation (mec-4, mec-10) did not increase, which suggests this enhanced locomotion depends in part on mechanosensory feedback. The worms sense of touch is likely important in how C. elegans navigate complex, structured environments.