in reply to extract sentences with certain number of a character

Yet another way to skin this cat (sorry for extending ww's animal metaphors...).

When I hear "count characters", grep in scalar context is usually the first thing to enter my brain.

use warnings; use strict; while (<DATA>) { print if ((grep /r/, split //) == 4); } __DATA__ r 3 r r rr 4 r r r r nada nothing zilch to many rr rrrr rrr 's

Not sure how this compares to others' regex and tr solution's from a performance standpoint (and I'm too Lazy to benchmark it :)