print $1 while $s =~ m[(.+?)(?=stop)]g;; this is a load of junk to be consumed until we get to the word stop. After that nothing should stop it until another