$x = "dog 789 cat dog dog bird cat wonder dog frog cat"; @finds = ($x =~ /((?:dog)(?:.*?)(?:cat))/g); #### $finds[0] = dog 789 cat $finds[1] = dog dog bird cat $finds[2] = dog frog cat