in reply to g matching after a single regular match

By the way, local $_; is dangerous (i.e buggy) in some circumstances (when the caller uses /\G.../ or pos($_) and when $_ is aliased to a tied variable). Use local *_ = ...; or for (...) instead.

sub func { # Any changes to $_ will affect the caller's var. local *_ = \$_[0]; ... }
sub func { my ($s) = $_[0]; # Safe. local *_ = \$s; ... }
sub func { # Any changes to $_ will affect the caller's var. for ($_[0]) { ... } }
sub func { for (my $s = $_[0]) { # Safe. ... } }