We investigate the dynamics of textbf{textit{Lumbriculus variegatus}} in water-saturated sediment beds to understand limbless locomotion in the benthic zone found at the bottom of lakes and oceans. These slender aquatic worms are observed to perform elongation-contraction and transverse undulatory strokes in both water-saturated sediments and water. Greater drag anisotropy in the sediment medium is observed to boost the burrowing speed of the worm compared to swimming in water with the same stroke using drag-assisted propulsion. We capture the observed speeds by combining the calculated forms based on resistive-force theory of undulatory motion in viscous fluids and a dynamic anchor model of peristaltic motion in the sediments. Peristalsis is found to be effective for burrowing in non-cohesive sediments which fill in rapidly behind the moving body inside the sediment bed. Whereas, the undulatory stroke is found to be effective in water and in shallow sediment layers where anchoring is not possible to achieve peristaltic motion. We show that such dual strokes occur as well in the earthworm textbf{textit{Eisenia fetida}} which inhabit moist sediments that are prone to flooding. Our analysis in terms of the rheology of the medium shows that the dual strokes are exploited by organisms to negotiate sediment beds that may be packed heterogeneously, and can be used by active intruders to move effectively from a fluid through the loose bed surface layer which fluidize easily to the well-consolidated bed below.