perl solution #29