#!/usr/bin/perl use strict; use warnings; use List::Util qw(shuffle); use File::Basename; print $_->[1] . $_->[0] . $_->[2] for sort { $a->[1] cmp $b->[1] || $a->[0] cmp $b->[0] || $a->[2] cmp $b->[2] } map { [ fileparse($_, qr/\.[^.]*/) ] } shuffle (); __DATA__ / /abc/ /abc/tes.pl /abc/test_5 /abc/test_42 /abc/test_foo.txt /abc/test_foo-2.txt /abc/test_foo01.txt /abc/test_foo_1.txt /abc/test/ /abc/test/z.php4 /abc/test/z.txt /abc-test/abc /asdf/ /asdf/123/ /asdf/A/ /asdf/B/ /asdf/B/C/ /asdf/B/C/a.file /home/ /home/test/ /home/test/asdf/ /home/test/asdf/jklo/ /home/test/asdf/jklo/rstuv2/ /home/test/asdf/jklo/rstuvw11/ /root/config /root/tmp/