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


in reply to Non-destructive string substitution

The key is to copy the data you want to preserve. If you need this kind of behaviour very often, write a simple subroutine that does what you want.

sub cdo(&$){ local $_ = $_[1]; $_[0]->(); $_ } my $foo = 'abc'; print cdo { s/abc/def/ } $foo; print "\n$foo\n";

TI, of course, MTOWTDI.

--
http://fruiture.de