in reply to Printing to file

It looks like you have a few problems with that code. If you want it to work with warnings and strict enabled then:
my $last_4_chars = '0001'; my @all_stores = map { # This sas file will seperate the datasets by stores # Opens file to write to open my $fh, '>', "weekly_${_}_pdf.sas" or die "Cannot open weekly +_${_}_pdf.sas: $!"; [ $_, $fh ] } qw( 24 25 ); for my $store ( @all_stores ) { print { $store->[ 1 ] } <<STORE; libname bce '/cdw/dept/dss/home_dir/s006258/BCE'; proc sql; SELECT FILEDATE,RPTSTORE,RPTTEAM,FIRSTNAME,LASTNAME,WTDTRAN, WTDOFFERS,WTDAPPS, substr(WTDOFFERS/WTDAPPS,0,5) as WTD_RATE, (case when (substr(sum(WTDAPPS)/sum(WTDOFFERS),0,4)*100) >= 1.2 then + 'G' when (substr(sum(WTDAPPS)/sum(WTDOFFERS),0,4)*100) <= 1.2 and (substr(sum(WTDAPPS)/sum(WTDOFFERS),0,4)*100) >= .65 then + 'Y' when (substr(sum(WTDAPPS)/sum(WTDOFFERS),0,4)*100) < .65 then +'R' end) as WTD_Color MTDTRAN,MTDOFFERS,MTDAPPS, substr(MTDOFFERS/MTDAPPS,0,5) as MTD_RA +TE, (case when (substr(sum(WTDAPPS)/sum(WTDOFFERS),0,4)*100) >= 1.2 then + 'G' when (substr(sum(WTDAPPS)/sum(WTDOFFERS),0,4)*100) <= 1.2 and (substr(sum(WTDAPPS)/sum(WTDOFFERS),0,4)*100) >= .65 then + 'Y' when (substr(sum(WTDAPPS)/sum(WTDOFFERS),0,4)*100) < .65 then +'R' end) as MTD_Color FROM bce.yearly_g${last_4_chars}v00 WHERE RPTSTORE = $store->[0] Order by RPTTEAM STORE } close $_->[ 1 ] for @all_stores;