D:\>perl -MYAPE::Regex::Explain -e"print YAPE::Regex::Explain->new(shift)->explain" "/((?:(?:[^\n@]+|@[^@]*@)\n?)+)/gs" The regular expression: (?-imsx:/((?:(?:[^\n@]+|@[^@]*@)\n?)+)/gs) matches as follows: NODE EXPLANATION ---------------------------------------------------------------------- (?-imsx: group, but do not capture (case-sensitive) (with ^ and $ matching normally) (with . not matching \n) (matching whitespace and # normally): ---------------------------------------------------------------------- / '/' ---------------------------------------------------------------------- ( group and capture to \1: ---------------------------------------------------------------------- (?: group, but do not capture (1 or more times (matching the most amount possible)): ---------------------------------------------------------------------- (?: group, but do not capture: ---------------------------------------------------------------------- [^\n@]+ any character except: '\n' (newline), '@' (1 or more times (matching the most amount possible)) ---------------------------------------------------------------------- | OR ---------------------------------------------------------------------- @ '@' ---------------------------------------------------------------------- [^@]* any character except: '@' (0 or more times (matching the most amount possible)) ---------------------------------------------------------------------- @ '@' ---------------------------------------------------------------------- ) end of grouping ---------------------------------------------------------------------- \n? '\n' (newline) (optional (matching the most amount possible)) ---------------------------------------------------------------------- )+ end of grouping ---------------------------------------------------------------------- ) end of \1 ---------------------------------------------------------------------- /gs '/gs' ---------------------------------------------------------------------- ) end of grouping ---------------------------------------------------------------------- D:\>