in reply to $1 into an array

try defining slotarray as a hash, which is how you are trying to use it in the assignment. Then you need to access it as a hash, not an array, when you try to print to outfile. If the problem is that $1 is empty then your regexp is not matching, and i suggest tweaking that.
#open files here my $counter = 0; my %slotarray; while ( <DPSLOTFILE> ) { my $dpdrivloc = "MSL6000 Trinity"; if ( /\Q$dpdrivloc\E:\s*(\d+)/ ) { $slotarray{$counter} = "$1"; #print OUTFILE "$1"; $counter++; } } foreach my $key (keys %slotarray) { print OUTFILE "$key: $slotarray{$key}\n"; } #close files here