my $output_dir = 'output/'; foreach my $file (@files) { print $file . "\n"; #Parse the file here open(FH, '>>', $output_dir.$file ) or die "Unable to open the file: $!"; print FH "Output goes into output directory with the same file name\n"; close(FH); }