open(FILE, "2.txt") or die("can't open myfile.txt: $!\n"); #### open FILEHANDLE, "> output.txt" #### open FILEHANDLE, ">> output.txt" #### $folder = '/tmp'; opendir TMPDIR, $folder or die "can't opendir $folder: $!\n"; while ( $filename = readdir TMPDIR ) { next unless $filename =~ /\.txt$/i; open FILE, "$filename" or die "can't open $filename: $!\n"; while() { if ($_ =~ /\s+(\S+)\s+(\S+)/) { $hash{$1} = $2; push(@index,$1); push (@a2, $2); } } close(FILE); # now do whatever } closedir TMPDIR; #### #!/usr/bin/perl -w # Even though W32 doesn't process the #! portion, I believe it # is smart enough to know that your inclusion of '-w' at the end # means that you want warnings reported. use strict; my $folder = '/tmp'; opendir TMPDIR, $folder or die "can't opendir $folder: $!\n"; while ( my $filename = readdir TMPDIR ) { next unless $filename =~ /\.txt$/i; my ( %hash, @index, @a2 ); open FILE, "$filename" or die "can't open '$folder/$filename': $!\n"; while() { if ($_ =~ /\s+(\S+)\s+(\S+)/) { $hash{$1} = $2; push(@index,$1); push (@a2, $2); } } close(FILE); # now do whatever } closedir TMPDIR;