perl solution #24