#!/usr/bin/perl use warnings; use strict; use File::Find; open my $log, '>', 'log.txt' or die "Can't open the log file!: $!"; find(\&check_data, "./test"); sub check_data { my $file = $_; #for clarity return if ! -f $file; open my $fh, '<', $file or die "Can't open file $file: $!"; for my $line (<$fh>){ if ($line =~ /^HELLO/){ my @parts = split(/\//, $line); for my $index (qw(1 3 4)){ if (! $parts[$index] or $parts[$index] =~ /[\s+-]/){ print $log "$file is missing data.\n"; return } } } } }