http://www.perlmonks.org?node_id=314685


in reply to $_ and list flattening with map()

$_++ for map @$_, @{$a};
The difference is that you do the increment outside of the scope in which map aliases $_. This foreach is iterating over the return value of map, which is a list of copies (not aliases back into @$a). foreach now aliases $_ to this anonymous list of copies, so your modifications to $_ are lost.

If you use map as a control structure (making it more of a direct translation of the first example), and do the increment inside map's block, you'll get what you expected originally:

map { map { $_++ } @$_ } @$a;

blokhead