Algorithms using Perl for quick solutions