Your declarations are lexical in scope and vanish at the end of the enclosing block. Since your my declarations take place in two different blocks and you then try to access them in a third they're no longer valid. You need to declare them in the largest enclosing scope (in this case you'd want to do so at the top of the while loop outside all branches of your conditional).
On an unrelated note, using undef rather than a junk variable is better practice if you don't need one of the return values from split (or wrap the split in parens and subscript it to pull out what you want, e.g. ( $foo, $bar ) = ( split( /:/ ) )[1,4]).