Thank you toolic for your great help although I need to read more about "unless".
I am not sure I understand it totally. I tested the script and for some reason it only reads the first text files in the directory (they are all text files). How I can generate a text files in the output for every text files that it reads in?
#!/usr/bin/perl
use strict;
use warnings;
my $dir="C:/move/output/test";
opendir DIR, $dir or die "Unable to open $dir: $!";
while (my $filename=readdir DIR)
{
my $file="$dir/$filename";
next unless -f $file;
open my $fh, '<', $file or die "Unable to open $filename: $!";
open OUT,">C:/move/output/test/out.txt";
select OUT;
my (variables);
{ my loop}
close $fh;
}