simple implementation of Markov algorithm in Perl