in reply to greedy subexpression between two nongreedy ones

Have you considered testing for 'cd' in the replacement?

s/,(.*?),/=@{[$1 =~ m|(cd)| && $1 ]}=/

Replies are listed 'Best First'.
Re^2: greedy subexpression between two nongreedy ones
by raygun (Scribe) on Jun 02, 2015 at 23:48 UTC

    I had not -- because I had no idea such a thing was possible. (So many Perl tricks to learn!) In fact, I still don't know how to find out more about this, because it's impossible to search Perl docs for a "@" and home in on a specific meaning. :-) What's the name of that @{ } construct?

    This solves my problem perfectly, and has the bonus of not further cluttering the left-hand side of an already complex substitute pattern. Thanks for the new trick!

      @{[...]} is a trick for interpolation of almost any expression into a string, explained e.g. here.

        Ah, so it's not really a new operator so much as a novel combination of familiar operators. Anyway, a great tool to have in one's toolbox!
      What's the name of that @{ } construct?

      According to perlsecret @{[ ]} is the "baby cart" operator.