#!/usr/bin/perl use strict; use warnings; my $basedir='/path/to/files/'; my @filelist=qw(irgenwas12 irgenwas34 irgenwas56 irgenwas78 irgenwas90); for my $file (@filelist) { my $date=''; my $name=$file; open(my $fh, '<', $basedir.$file) or die("ERROR open $basedir$file ($!)\n"); while(my $line=<$fh>) { ($date)=$line=~/^\{datestamp=(\d{12})\}/); last if($date); } close($fh); $file={name=>$name,date=>$date}; } @filelist=sort{$a->{date} cmp $b->{date}}@filelist; for my $file (@filelist) { print $file->{name}; print $file->{date}?' ('.$file->{date}.')':' (NO DATE FOUND)'; print "\n"; }