use strict; use Data::Dump qw(dump); my @packeddirs = qw'verz1/datei4 test verz1/verz2/verz3/file3 verz1/file2'; my @unpackeddirs = map { [split '/', $_] } @packeddirs; my @sorteddirs = sort { my $idx = 0; my $res = 0; while(!$res) { $res = sort_unpacked($idx++, $a, $b) } $res; } @unpackeddirs; sub sort_unpacked { my ($idx, $left, $right) = @_; my $ma = $left->[$idx]; my $mb = $right->[$idx]; defined $ma and defined $mb ? $ma cmp $mb : defined $ma ? 1 : -1; } dump @sorteddirs;