Added perl version, algorithm is quite the same