At first glance...
Your code returns $2nd as a string but your case is looking for integer.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.