use strict; use warnings; #open files here #my $counter = 0; my @slotarray; while ( ) { my $dpdrivloc = "MSL6000 Trinity"; if ( /\Q$dpdrivloc\E:\s*(\d+)/ ) { #my $slotarray{$counter} = "$1"; #print OUTFILE "$1"; #$counter++; push @slotarray, $1; } } for (@slotarray) { #print OUTFILE "$slotarray\n"; print OUTFILE $_,$/; } #close files here