in reply to Global vs. Local Variables Assistance Requested

Consider making slightly more use of your program's memory.

my %command; my $destination; while(<DATA>) { # assign split results to named scalars my ($ignored, $file, $flag) = split /,/; if ($flag =~ /^[CD]$/) { $destination = $file; $command{$destination} = "type $flag"; } $command{$destination} .= " $file.txt"; } for my $destination (sort keys %command) { # Look, only one print statement! print "$command{$destination} > $destination.txt\n"; } __DATA__ IM,BEN01,D,0 IM,BEN02,D,0 IM,BEN03, ,0 IM,BEN04, ,0 IM,BEN05, ,0 IM,BEN06,C,0 IM,BEN07, ,0 IM,BEN08, ,0 IM,BEN09, ,0 IM,BEN10,D,0