How does global matching /g affect performance or memory usage?

In Perl, the global matching modifier `/g` allows a regex to find all occurrences of a pattern within a string, instead of stopping after the first match. However, using `/g` can have both performance and memory implications, especially with larger datasets or complex regex patterns.

Perl, global matching, performance, memory usage, regex, /g modifier

<?php // Example of using global matching in Perl $string = "The quick brown fox jumps over the lazy dog. The dog was not amused."; // Find all occurrences of 'dog' in the string @matches = ($string =~ /dog/g); // Output matches print "Matches: @matches\n"; ?>

Perl global matching performance memory usage regex /g modifier