use FileHandle; use strict 'vars'; my @files; my $fileCount = 0; my $file; my $tmp; my $f; # Create the files for (my $i = 0; $i < 520; $i++ ) { open(TOUCH, "touch cb$i.txt|") or die "could not touch the file $i"; close(TOUCH); } # open the dir handle opendir(CURRENT, ".") or die "Could not open the current dir"; # open all files that start with "cb" while ($file = readdir(CURRENT)) { if($file =~ /^cb/) { print "Open File Nr.: $fileCount $file\n"; ### use the FileHandle $tmp = new FileHandle($file, "w") or die "could not open $file"; push(@files, $tmp); ### ### Comment in to use the normal open function of perl # open($file, ">$file") or die "error 1"; # push(@files, $file); ### $fileCount++; } } # Write one line in each file and close the file foreach $f (@files) { ## Use the FileHandle $f->print("Hi my name is $f"); $f->close() or die "error 2"; ## Comment in to use the normal open function of perl # print $f ("Hi my name is $f"); # close($f) or die "error 2"; }