use strict; use warnings; use IO::Handle; use File::Basename; use File::Find; use File::Copy; my $fh; my $fh2; my $jj; my $file; my $line; print "I'm in trim\n"; print "curent working directory is $ENV{PWD}, \n"; open ($fh, ">", "output2.txt") or die "$!"; print $fh ""; close $fh; chdir "../Html3"; print "curent working directory is $ENV{PWD}, \n"; my @files2 = grep { -f } glob("*.txt"); foreach $file (@files2) { open (FILE, "$file"); while($line= ){ open ($fh2, ">>", "output2.txt") or die "$!"; if ($line =~ m/^[A-Z]'?[- a-zA-Z]+$/) {print $fh2 "$line";} if ($line =~ m/^[A-Z]'?[- a-zA-Z]+$/) {print "$line";} } close FILE; } die;