Your local($_); is producing an undef $_. The match at the end of the grep block is producing a list of the @foo which start with t or T. The $_ grep provides is the external one, not your substituted one.
You can do what you want with a combination of map and grep my @m_h = map {(my $c = $_) =~ s/$this/$that/ig; $c } grep {/^t/i} @foo; or, maybe, my @m_h = grep {/^t/i} map {(my $c = $_) =~ s/$this/$that/ig; $c } @foo; That will leave @foo undamaged.
After Compline,
Zaxo
In reply to Re: Localize $_ in grep
by Zaxo
in thread Localize $_ in grep
by InfiniteSilence
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |