my %strcmp; # get the uniq list open( DF, "logfile.log" ); while() { chomp; $data{(split(" ",$_))[2]}++; } close(DF); my @keys = sort {$data{$b}<=>$data{$a}} keys %data; @keys = splice(@keys,0,4000); open( OUT, ">temp.dat" ); foreach my $line ( @keys ) { print OUT "$line\n"; } close( OUT ); # create the list of strings matching the patterns open(IN, "$outputfile"); while() { chomp(); # matche data foreach my $regexp ( keys %regexp ) { $strcmp{$_} = $regexp{$regexp} if ( $_ =~ m/$regexp/ ); } } close( IN ); # applie this to the logfile open( IN, "logfile.log" ); open( OUT, ">logfile_parsed.log" ); while() { chomp; my @cols = split(" ",$_); next if( exists $strcmp{$cols[2]} ); print OUT "$_\n"; } close( OUT ); close( IN ); move( "logfile_parsed.log", "logfile.log" ); # from here more or less the same as the first perl listing.