#!/usr/bin/perl -w use strict; use warnings; use Text::ParseWords; opendir IN, 'Outpatient'; my @in = grep { /\.txt$/ } readdir IN; # read all file names form dir except names started with dot closedir IN; for my $in (@in) { open IN, '<', "Outpatient/$in" || next; open OUT, '>', "TXT/$in" || die "can't open file Formatted/$in"; while() { my @f = quotewords ',', 0, $_; print OUT join "," => @f; } close OUT; close IN; } INPUT FILE: """555522""",MEN'S HEALTH DEPARTMENT,"""12/31""" OUTPUT FILE: **BLANKS EXPECTED OUTPUT: 555522,MEN'S HEALTH DEPARTMENT,12/31