$f="chapter 1,2,3"; if($f=~m/chap( |[a-z])*([,0-9]+)/i) { print join ", ", map { "chapter $_" } split /,/,$2; }