http://www.perlmonks.org?node_id=1010463


in reply to Replacing with comma

You have been given great answers, but If I may add just this.
Using a subroutine with scalar, reverse functions with substitution s///. One can hack a solution like so:

use warnings; use strict; my $foo = "1,2,3"; print modify( $foo, ',', '|' ); ## prints 1,2|3 $foo = "1|2|3"; print modify( $foo, '|', ',' ); ## prints 1|2,3 sub modify { my ( $val, $sep, $rep ) = @_; $val = scalar reverse $val; $val =~ s/\Q$sep\E/$rep/; return scalar reverse $val; }

If you tell me, I'll forget.
If you show me, I'll remember.
if you involve me, I'll understand.
--- Author unknown to me