Various algorithms in Perl and Ruby