sub till { my $state = lookupState(caller); croak('Fatal: till: Too few conditions for current state.') if ((2 * $state) >= @_); if ref($_[2 * $state]) eq 'SCALAR' { $state++ if ($_[2 * $state]); } elsif ref($_[2 * $state]) eq 'Regexp' { $state++ if (/$_[2 * $state]/); } elsif ref($_[2 * $state]) eq 'CODE' { $state++ if ($_[2 * $state]->($_)); } saveState($state, caller); if ((2 * $state) >= @_) { # final condition was true saveState(0, caller); return 0; } return 0 if ($state < 1); # init condition still false return $_[2 * ($state - 1)]->($_); }