Coding problem or a bug in Asterisk(AGI)

I have a little DEADAGI script written in PERL that dials destination:

$dialstr = $type."/$dest@".$ip."|60" $res = $AGI->exec("DIAL $dialstr"); $result=$AGI->exec('NoOp',$answeredtime=$AGI->get_variable('ANSWEREDTIME'));
if for some reason $answeredtime=0 then we dial it again:

$dialstr = $type."/$dest@".$ip2."|60" $res = $AGI->exec("DIAL $dialstr"); $result=$AGI->exec('NoOp',$answeredtime2=$AGI->get_variable('ANSWEREDTIME'));
it works and the call goes to the second provider. The problem is that $answeredtime2 is always null or empty. I have tried everything but can not get the answeredtime for the second dial attempt.
Is this a bug or is it a coding problem. Please advise.
Thank you in advance.