Simplificate an array
Perl, 52 bytes

Just a recursive subroutine. (unusual for a Perl answer, I know..)

sub f{say"@{[grep!ref,@_]}";@_&amp;&amp;f(map/A/?@$_:(),@_)}


Call it like that :

$ perl -E 'sub f{say"@{[grep!ref,@_]}";@_&amp;&amp;f(map/A/?@$_:(),@_)}f(1, [2, 3], [[4]], [[[5, 6], 7, [[[8]]]], 9])'
1
2 3 9
4 7
5 6

8


Each line of the output corresponds to a depth level of the array (hence the empty line in the example above).

It can be turned into a full program for just a few more bytes : add -n flag and an eval (inside @{ } to transform the input into an array and not an arrayref) to transform the input into a Perl array :

perl -nE 'sub f{say"@{[grep!ref,@_]}";@_&amp;&amp;f(map/A/?@$_:(),@_)}f(@{+eval})' &lt;&lt;&lt; "[1, [2, 3], [[4]], [[[5, 6], 7, [[[8]]]], 9]]"




My previous approach was slightly longer (65 bytes), but still interesting, so I'll let it here :


perl -nE '/\d/?push@{$;[$d-1]},$_:/]/?$d--:$d++for/\[|]|\d+/g;say"@$_"for@' &lt;&lt;&lt; "[1, [2, 3], [[4]], [[[5, 6], 7, [[[8]]]], 9]]"