#!perl -w use strict; my $dir = 'C:\\some_directory'; my $out_file = 'Results.csv'; opendir my $dh, $dir or die "$!"; my @files = grep {/\.txt$/} readdir $dh; for my $file (@files) { open my $in, '<', "$dir/$file" or die "$file: $!"; while (<$in>) { if (/Works: /) { open my $out, '>>', "$dir/$out_file" or die "$out_file: $!"; print $out substr($_, 20) } } }