Port grade school exercise to perl5