$out = ""; while ($data =~ s#()(\w{3} ?)(.*?)(.*?)#$1$3#is) { $out .= $2. " " . $4 . "\n"; }