my ($bits, $state, $c, $n, $end) = ('', 0, undef, 0, '');
my $sighandler = sub {
my ($b) = @_;
if ($state == 2) {
if (defined $bits && (substr $bits, -$n) eq $end) { # done
substr $bits, -$n, $n, '';
my ($bits, $state, $c, $n, $end) = ('', 0, undef, 0, '');
my $sighandler = sub {
my ($b) = @_;
if ($state == 2) {
if (defined $bits && (substr $bits, -$n) eq $end) { # done
substr $bits, -$n, $n, '';