foreach my $file (sort {substr($a,4) <=> substr($b,4)} keys %hash) { print "$key \n"; }