Asterisk::AGI

I am developing an application using asterisk to allow the users to hear their email messages over their phone. I need to allow my users to press 0 whenever they would like to terminate the call. By using the Background application from the dialplan it works just fine. However, I need to allow them to press 0 whenever they would like to terminate the call while the AGI is executing. For instance, I have an agi script (written in perl) that accesses the user mail box and returns the number of unread messages the respective user has in its mail box. The script takes a while, and for not my users to get bored, I play for them a music in the background, and i do this using set_music from Asterisk::AGI module. (all this is embeded in the same agi script) what i i need is to be able to press zero and hangup the call while the music is playing, that is while the agi is executing, I have tried the wait_for_digit in the same perl module but it does not seem to work for me. That is, i need to make the agi script listen for the digit the user may press while executing