in reply to Non-destructive substitution?

You cannot avoid using a different variable.

The usual idiom is:

($tmp = $string) =~ s/foo/blah/;
If you want to combine it with calling a function, use Perls do:
func do {(my $tmp = $string) =~ s/foo/blah; $tmp};
Or
func do {local $_ = $string; s/foo/blah; $_};

-- Abigail

Replies are listed 'Best First'.
Re: Re: Non-destructive substitution?
by MeowChow (Vicar) on Jul 03, 2001 at 01:27 UTC
    Such a shame too, it would be nice if there were a "return substituted copy" modifer for s///, would make alot of golfs shorter :)
       MeowChow                                   
                   s aamecha.s a..a\u$&owag.print