use warnings; use strict; while(){ chomp; print grep{/.+?\!/} split } __DATA__ Mary had a little lamb! , whose fleece! was white! as snow. And everywhere! that Mary went, the lamb was sure! to go.