I'm guessing the second signal is only handled after the handler returns from handling the first signal, at which point local $SIG{$sig} has already been unwound. That should be easy to verify by putting a print at the top of handlesig and another at the bottom.