in reply to Replace a hash key if it matches a regex

Assuming you need to keep characters upto one more than the first occurence of "-"

s/-./$`$&/;

Replies are listed 'Best First'.
Re^2: Replace a hash key if it matches a regex
by AnomalousMonk (Archbishop) on Sep 13, 2013 at 09:11 UTC

    That doesn't seem to work:

    >perl -wMstrict -le "$_ = 'BLAH01-ARRRGH0GAG'; s/-./$`$&/; print qq{'$_'}; " 'BLAH01BLAH01-ARRRGH0GAG'

    Update: If  \K is available (5.10+), this works nicely:

    >perl -wMstrict -le "use 5.010; ;; $_ = 'BLAH01-ARRRGH0GAG'; s{ .*? - \w \K .* }''xms; print qq{'$_'}; " 'BLAH01-A'