Please excuse the test message in reply to Paul's Message. I did some printf's in the code to test the output. The result Paul is seeing is only on the first record and it's happening in the first occurance of:
my $firstDir = substr ($patientId...
if I print the values of $patientId and $hospitalId before the substr the data appears to be correct.
I also tried something since the data is numeric in nature. I tried:
my $patientId = int $ids[0];
which resulted in the following as an error since it's not text.
M-oM-;M-?514027
So it appears to be something that's happening with the substr and the data in the file. I see no special characters in the file itself using vi :set list I also did a dos2unix on the file to make sure it's using the right format. I have read that there are problems with perl and files in UTF-8 format. Is that a potential problem?