#!perl use strict; use warnings; use autodie; # die if problem reading or writing a file use feature qw(say); my $input = "C:/Some/specific/path/to/file.txt"; open FILEin, $input; my @input = ; binmode(FILEin); undef $/; foreach $input (@input) { my $dir = 'C:/Some/specific/folder'; my @files = <$dir/*>; my $countf = @files; my $outfile = $dir.'/bladibla_'.$countf.'.txt'; open FILEout, '>'.$outfile; print FILEout $input; close FILEout; say 'Wrote '.$input.' to '.$outfile; } close FILEin;