perl solution #18