print mine ("Terence and Philip are sweet", 'c', 'Z', 3);
####
sub crep {
my ($str, $chr, $rep, $nth) = @_;
my $pos = 0;
while (--$nth > 0) {
$pos = index $str, $chr, $pos;
last if $pos < 0;
$pos++;
}
substr ($str, $pos) =~ s/$chr/$rep/g if $pos >= 0;
return $str;
}
##
##
sub crep {
my ($str, $chr, $rep, $num) = @_;
my $tstr = '';
$tstr .= substr $str, 0, (1 + index $str, $chr), '' while --$num;
$str =~ s/$chr/$rep/g;
$tstr.$str;
}
##
##
sub crep {
my ($str, $chr, $rep, $num) = @_;
$str !~ /$chr/g and return $str while $num--;
substr ($str, -1 + pos $str) =~ s/$chr/$rep/g;
return $str;
}
##
##
sub crep {
my ($str, $chr, $rep, $nth) = @_;
my $pos = 0;
($pos = index $str, $chr, $pos)++ < 0 and return $str while --$nth;
substr ($str, $pos) =~ s/$chr/$rep/g;
return $str;
}