chomp(@file_array); open(RECENT, ">>$installpath/recent"); # or just > foreach $filename (@file_array) { open(FH, "< $filename") or warn "Could not open $filename: $!"; while () { if (/$search_value/o) { print RECENT "$search_value=$filename--> $_"; $numhash{$search_value}++; $matched++; } } close(FH); } close(RECENT);