perl solution #39