in reply to Replace all occurrences but the last

join _=>split/[.]/=>$_,y[.]__;

Replies are listed 'Best First'.
Re^2: Replace all occurrences but the last
by Aristotle (Chancellor) on Aug 23, 2004 at 11:08 UTC

    Silly rabbit. :-) Nice approach, though.

    # legible: join( "_", split( /\./, $_, y/.// ) );

    The tr/// here counts the dots in the string and uses the number as a limit to split — since the number is one less than the number of fragments delimited by dots, the last dot in the string does not get to serve as a delimiter.

    Makeshifts last the longest.