my @ary = ( 1, 2, 3 ); for (@ary) { $_ = check($_); } # now flatten the list of mixed array refs and scalars into one list my @tmp; push @tmp, ref $_ ? @$_ : $_ for @ary; @ary = @tmp; print "$_\n" for @ary; sub check { return $_[0] == 2 ? [ 'a', 'b', 'c' ] : $_[0]; } __DATA__ 1 a b c 3