#initiate a loop counter $loop = 0; #using for loop to get rid of new line in the array for (@array){ $array[$loop] =~ s/\n//; $loop++ }