fixed solution to problem 25 in perl