$val[2] gives the third element of @val.
In reply to Re^3: Store the outcome of a foreach loop in an array by pryrt in thread Store the outcome of a foreach loop in an array by perl_5eeker