for ( $i = 0; $i < 4; ++$i ) { # if the element is not defined, assign it a value if ( ! defined( $array[ $i ] ) ) { $array[ $i ] = "happy"; } } print "@array\n"; print @array, "\n";