#count the files in my foreach loop (I'm in a foreach loop, #not shown, that loops through @files my $count = @files; my @count = (); # I'l explain what I want to do with this - Note 1. push (@count, $count); print $count; print "\n"; #now this is where I am creating my new files, getting data from the #files in the foreach loop my $pdb; open (my $pdb, '>', "$filename.pdb"); my $p; my $w; my $title = "$filename"; my $bx = 50.000; my $by = 50.000; my $bz = 50.000; printf $pdb "%s$title"; printf $pdb "\n"; printf $pdb ("%5d",$atomcount); printf $pdb "\n"; for ($p=1; $p<=$atomcount; $p++) { my $carboxyl = "@count[$w]"; #here is all that I want to do-Note 2 printf $pdb("%5d%-5s%5s%5d%8.3f%8.3f%8.3f",1,$carboxyl,@atom[$p],$p,@x[$p],@y[$p],@z[$p]); printf $pdb "\n"; } printf $pdb("%10.5f%10.5f%10.5f",$bx,$by,$bz); printf $pdb "\n"; close $pdb/;