perl solution #31