How can I golf this Perl subroutine that does a substitution?

Posted by JoelFan on Stack Overflow See other posts from Stack Overflow or by JoelFan
Published on 2010-02-15T16:27:38Z Indexed on 2010/04/25 5:43 UTC
Read the original article Hit count: 136

Filed under:

I have the following subroutine in Perl to substitute "abc" for "xyz" in a string:

sub mySubst {
    my ($str) = @_;
    $str =~ s|abc|xyz|ig;
    return $str;    
}

It works, but seems way too verbose for Perl. How can I tighten it up?

© Stack Overflow or respective owner

Related posts about perl