use 5.18.0; use File::Slurp; use File::Find ; use Cwd ; my $topDir = "/Users/Henry/Documents/WACS/en_ulb"; my %found; my @filesToRun = (); my $filePattern = '*.usfm' ; open LOG, ">/Users/Henry/Google Drive/WA/Scripts/out/log.log" or die; open OUT, ">/Users/Henry/Google Drive/WA/Scripts/out/output.txt" or die; find( sub { push @filesToRun, $File::Find::name if ( m/^(.*)$filePattern$/ ) }, $topDir) ; foreach my $file ( @filesToRun ) { print "$file\n" ; my $fileText = read_file("$file", binmode => 'utf8'); $fileText =~ s/\n/ /g; while ($fileText =~ /(\\[^ ]*) /g) { my $code = $1; unless (exists $found{$code}) { $found{$code} = $code } } } foreach my $code (sort keys %found) { say OUT $code } close OUT; close LOG; print "\n\tDone."