There are several good answer aboves. I just wanted to point out that you must have made a mistake transcribing the code. You're assigning values to $string1 and $string2, but using split on a different variable $string (no number). The code as you have it here sets both $var2 and $var4 (and the others) to undef.