#!/usr/bin/perl -w use strict; use File::Find; use File::Basename; my $start_dir = "C:/temp"; my $log_file = 'C:/temp/logfile.txt'; open (my $log, '>', $log_file) or die "cannot open $log_file for write"; find (\&process_file, $start_dir); sub process_file { return unless -f; # do not process directories, # only "real files" my $full_path_name = $File::Find::name; print "$full_path_name\n"; #other ways of writing the "if", but extending your code if ( -s == 0 and ($_ ne 'empty.txt') and ($_ ne 'sample.txt') and ($full_path_name ne $log_file) ) { print $log "Warning: $full_path_name has size ZERO\n"; } }