Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hi, I need to replace the nth occurence of a character in a string.Currenly m tryng to replace the 2nd comma in ths string.I have used the following code for that.Can anyone give a better suggestion?

my $count = 3; my $str = "a,b,c,d"; $str =~ s/(,)/--$count == 1 ? "|":$1/ge; print $str;