perl -e 'print map {++$count," : ",$_,"\n"}split /(a|b)+/,"a12cdabab"' 1 : 2 : a 3 : 12cd 4 : b