#! /usr/bin/perl use strict; use warnings; my %files; my $dir_alt = 'C:\Users\alt'; my $dir_neu = 'C:\Users\neu'; read_files(\%files,'$dir_alt'); read_files(\%files,'$dir_neu'); my @sorted=map{$_->[0]}sort{$a->[1] <=> $b->[1]}map{[$_,(/(\d+)/)]}keys(%files); sub read_files { my $files=shift; my $dir=shift; opendir(my $dh, $dir) or die("error opedir $dir ($!)\n"); while(my $file=readdir($dh)) { next unless($file=~/\d+\.txt/); push(@{$files->{$file}},$dir); } closedir($dh); }