sub work_with_file { my ( $filename, $addon ) = @_; if ( open( FILE, "< $filename" ) ) { while () { $Datum = $_ if m/Date: /; $Zeit = $_ if m/Time: /; $errorFound = 1 if /Severity: Error/; $lines .= $_; #generate a new hash-hey if ( $Zeit && $Datum && $errorFound ) { $Zeit =~ s/\D//g; $Datum =~ m/(\d+)\.(\d+)\.(\d+)/g; $dt = $3 . $2 . $1 . $Zeit . "_" . $addon; $Datum = $Zeit = ""; } #put the error snippel in hash if ( /^\s*$/ or eof ) { $hash{$dt} = $lines if $errorFound; $errorFound = 0; $lines = ''; } } close(FILE); } } work_with_file($file1, ARGV[0]); work_with_file($file2, ARGV[1]);