in reply to Issue with Loop when Apostrophe in Field

my @in = grep { /\.txt$/ } readdir IN; # read all file names form dir +except names started with dot

Your code does not exclude file names that start with a dot (hidden files). To do that you need this:

my @in = grep { !/^\./ && /\.txt$/ } readdir IN; # read all file names + from dir except names started with dot
open IN, '<', "Outpatient/$in" || next; open OUT, '>', "TXT/$in" || die "can't open file Formatted/$in";

Your opens will not fail correctly because of the high precedence of the || operator.

You need to either use the or operator (low precedence):

open IN, '<', "Outpatient/$in" or next; open OUT, '>', "TXT/$in" or die "can't open file Formatted/$in";

Or use parentheses:

open( IN, '<', "Outpatient/$in" ) || next; open( OUT, '>', "TXT/$in" ) || die "can't open file Formatted/$in";