Grabbing some data afther the call ends. dial option g

hello everyone.

im running a perl agi, and inside it im calling a dial command.

the point is, that i want the agi to continue running after the call ends, to grab some statistic data.

im using the dial option “g” but this only works when the called party hangs up.
if the caller hangs first, then it doesnt work.

is there a run around for this?
any ideas?

btw, im using asterisk 1.6.1
thanks in advance