my @matches = (m/(.*?)(.*?(?=))/gx); # Should work. my @matches = (m/(.*?)(.*?(?=))/gx); # Should also work. my @matches = (m/(.*?)(.*?(?=))/gx); # Probably more robust like this.