use warnings; use strict; my $text = <<'END'; one test two three END # m//g in scalar context while ($text=~ m{]*>((?:(?!).)*)}sg) { print "a: \"$1\"\n"; } # m//g in list context my @m = $text=~ m{]*>((?:(?!).)*)}sg; print "b: \"$_\"\n" for @m; __END__ a: "one" a: " two " a: "three" b: "one" b: " two " b: "three"