perl solution #40