my @output_data_files = qw( filename1 filename2 more_filenames... ); my $pattern = qr/result/; # a regular expression that will find "result" my @results_found; # here goes everything that was found. foreach my $file ( @output_data_files ) { open ( FILE, "< $file" ) or die qq(could not open file "$file" for reading: $!); while ( ) { # on every line of the file if ( my @matches = m/$pattern/g ) { # matches of the pattern push @results_found, @matches; # add them to @results_found } } close FILE; }