perl -wle'use YAPE::Regex::Explain; my $re = qr/\W*(\w+\W+){1,2}\w+\W*/; print YAPE::Regex::Explain->new($re)->explain;' The regular expression: (?-imsx:\W*(\w+\W+){1,2}\w+\W*) 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): ---------------------------------------------------------------------- \W* non-word characters (all but a-z, A-Z, 0- 9, _) (0 or more times (matching the most amount possible)) ---------------------------------------------------------------------- ( group and capture to \1 (between 1 and 2 times (matching the most amount possible)): ---------------------------------------------------------------------- \w+ word characters (a-z, A-Z, 0-9, _) (1 or more times (matching the most amount possible)) ---------------------------------------------------------------------- \W+ non-word characters (all but a-z, A-Z, 0-9, _) (1 or more times (matching the most amount possible)) ---------------------------------------------------------------------- ){1,2} end of \1 (NOTE: because you are using a quantifier on this capture, only the LAST repetition of the captured pattern will be stored in \1) ---------------------------------------------------------------------- \w+ word characters (a-z, A-Z, 0-9, _) (1 or more times (matching the most amount possible)) ---------------------------------------------------------------------- \W* non-word characters (all but a-z, A-Z, 0- 9, _) (0 or more times (matching the most amount possible)) ---------------------------------------------------------------------- ) end of grouping ----------------------------------------------------------------------