How do you use capturing groups with a short example?

Capturing groups in Perl allow you to extract specific portions of a string that match a certain pattern. They are created by placing parentheses around the part of the pattern you want to capture.
capturing groups, perl, regex, pattern matching
# Example of capturing groups in Perl my $string = "The quick brown fox jumps over the lazy dog"; if ($string =~ /(\w+) (\w+)/) { print "First word: $1\n"; # Captured first word print "Second word: $2\n"; # Captured second word }

capturing groups perl regex pattern matching