use strict; use warnings; use File::Find; use File::Copy; use autodie; my $log = q(C:\target\copylog.csv); my $target = q(C:\target); my $pattern = qr(SearchWord); close *STDERR; open *STDERR, '>', $log; find( sub { if (-f) { open my $file, '<', $_; while (my $line = <$file>) { if($line =~ m/$pattern/ig) { copy ($_, $target); warn "$_, $pattern\n"; last; } } close $file; } }, glob ('Z:\Linux\site') ); #### use strict; use warnings; use autodie; use Path::Tiny; use Path::Iterator::Rule; my $source = q(Z:\NEW\STUFF); my $pattern = qr(hello.*world); my $destination = q(C:\Users\loops\Desktop\stuff); close *STDERR; open *STDERR, '>', 'copylog.csv'; my $rule = Path::Iterator::Rule->new; $rule->file->line_match($pattern); my $next = $rule->iter( $source ); while ( defined( my $file = $next->() ) ) { eval { path($file)->copy($destination) }; print STDERR $@ ? "$@" : "$file, $pattern\n"; }