# using a Markov Chain, because this question itself as input text for example

Create a Markov Chain generator, which generates (and outputs) an Order 4 text chain. It must be able to support all plain text formatting used on this question, so be sure to check for punctuation (parentheses count for example, but HTML doesn't need to be accounted for fortunately)! You could even use this question itself as input if you're so inclined. There must be a defined input variable (or something analogous to such, I am aware certain popular esoteric languages do not really have variables per se.)

Your generator also should start sentences with a capital letter, and end with ".", "!", or "?", according to how often those respective characters appear in the input text.

You must also include a way to change the amount of text which should be output, so the only two things that are really configurable are the amount to output and the input string. It should stick with an Order 4 chain, because those happen to be funniest when it all comes down to it really.

Oh and, if your generators happen to create something particularly funny, please feel free to include it in your post for the lulz.

The title of this question was generated using a Markov Chain.

$/=$,;$_=<>;push@$1,$2while/(?=(....)(.))/sg;print+($m)=/(....)/s;print while($m.=($_=m[rand@\$m]))=~s/.//s