use strict; use warnings; use Cwd; my $cwd = getcwd(); #inputs# my $dir = "D:\\Temp"; my $fff; my @dir = (); my $contilog = "$cwd"."\\input.txt"; open(LOG,">",$contilog) || die "Cannot create log file ...."; opendir (DIR,$dir); @dir=readdir(DIR); closedir(DIR); @dir = sort(@dir); foreach $fff (@dir){ write_log("$fff"); } #### my $input = "$contilog"; #### #my $input = "$cwd"."\\input1.txt"; #### open my $fh, '<', $input or die "unable to open file: $!"; # read it line by line with while, using the $. variable to # show the line number (instead of your own counter). while( <$fh> ) { print "$_\n"; # LINE NO: LINE } print "$contilog\n"; print "$input\n"; print "Total lines was $.\n"; sub write_log{ print LOG @_; print LOG "\n"; } sub trim($) { my $string = shift; $string =~ s/^\s+//; $string =~ s/\s+$//; return $string; }