Using 'for' to traverse hash arrays instead of while