for ( $i = 1; $i <= 5; ++$i ) { push( @array, $i ); print "@array\n"; } while ( @array ) { $secondTotal += shift( @array ); # remove first element print "@array\n"; # display current @array } print "\$secondTotal = $secondTotal\n";