regexp = /[ \t]*([^\.\!\?])[ \t]*\n/ while l=gets l.gsub!(/[ \t]*<[^<>]*>[ \t]*/, "") l.capitalize! if regexp.match(l) then l.gsub!(/[ \t]*\n/, " .\n") end l.gsub!(/(.+)(\1)+/, '\1') puts l end