s/(.{5,12}\s+)/$1\n/g #### Check out http://www.perlmonks.org/?node_id=438189 (it has nice line-wrapping snippet).