in reply to Modifying 'next' in foreach loop

next is a command which tells perl to jump to the next iteration of the loop - it doesn't return the next value of the loop - neither as rvalue (not changeable) nor as lvalue (changeable). So you mixed something completely up here. See the solution posted by the monks before me.