in reply to Re^2: how to search and replace the match with specific number of times in a string
in thread how to search and replace the match with specific number of times in a string

your code does 2 replaces:
  1. * will be replaced by *\n => so your string is    *\n*ab***c
  2. again, the first * will be replaced by *\n, giving you    *\n\n*ab***c
If you want to continue your approach, a solution could be:
  1. replace * by some string not containing your search-pattern (e.g. X) $s=~s{\*}{X} for 1..2;
  2. replace the new string by your search-pattern $s=~s{X}{\*\n} for 1..2;

Or follow some other advice given in this thread...

HTH, Rata