in reply to how to search and replace the match with specific number of times in a string
perl -le '$s = "abcabdaaa"; $n = 3; print join( "i", split( /a/, $s, $ +n+1 ))' [download]