#pseudo-code $|++; #flush output to stdout as soon as possible my @files = glob '*.txt'; foreach my $file (@files){ my ($var_one, $var_two ...); #your var names to be checked open my $fh, '<', $file or die "..."; while (<$fh>) { #use regex to put something inside $var_one, $var_two } # if (all vars needed are defined and pass your check){ print "$file IS VALID\n"; system 'mv $file /new/path' } }