use YAPE::Regex::Explain; print YAPE::Regex::Explain->new( qr{hd_defect-( ([^\.]+$) | (?: ([^\.]+).(.+$) ) )}sx )->explain; __END__ The regular expression: (?sx-im:hd_defect-( ([^\.]+$) | (?: ([^\.]+).(.+$) ) )) matches as follows: NODE EXPLANATION ---------------------------------------------------------------------- (?sx-im: group, but do not capture (with . matching \n) (disregarding whitespace and comments) (case-sensitive) (with ^ and $ matching normally): ---------------------------------------------------------------------- hd_defect- 'hd_defect-' ---------------------------------------------------------------------- ( group and capture to \1: ---------------------------------------------------------------------- ( group and capture to \2: ---------------------------------------------------------------------- [^\.]+ any character except: '\.' (1 or more times (matching the most amount possible)) ---------------------------------------------------------------------- $ before an optional \n, and the end of the string ---------------------------------------------------------------------- ) end of \2 ---------------------------------------------------------------------- | OR ---------------------------------------------------------------------- (?: group, but do not capture: ---------------------------------------------------------------------- ( group and capture to \3: ---------------------------------------------------------------------- [^\.]+ any character except: '\.' (1 or more times (matching the most amount possible)) ---------------------------------------------------------------------- ) end of \3 ---------------------------------------------------------------------- . any character ---------------------------------------------------------------------- ( group and capture to \4: ---------------------------------------------------------------------- .+ any character (1 or more times (matching the most amount possible)) ---------------------------------------------------------------------- $ before an optional \n, and the end of the string ---------------------------------------------------------------------- ) end of \4 ---------------------------------------------------------------------- ) end of grouping ---------------------------------------------------------------------- ) end of \1 ---------------------------------------------------------------------- ) end of grouping ----------------------------------------------------------------------