foreach (@files) { my $file = $_; print join $/ => map{$_->[0]} sort{$a->[1] <=> $b->[1]} map{[$_,/.+?-(\d+)\..+$/]}$file; print "\n";