my $re = qr{ (?> # don't backtrack into this group !. # either the escape character, # followed by any other character | # or [^!;\n] # a character that is neither escape # nor split character )+ }x; while ($str =~ /($re)/g) { print "Chunk '$1'\n"; }