use strict; use warnings; use File::Path qw( make_path ); use File::Slurp; use Cwd; my $cwd = getcwd(); my @dirs = read_dir($cwd); for(@dirs){ next unless -d $_; make_path( "$cwd/result/$_" ); open (my $file, '>', "$cwd/result/$_/test file for $_.txt") or die "$!"; print $file "this is a test for directory $_"; #or print calculation to $file }