sub getAnyAll { my $code = shift; my $Any = sub { my @A = @{$_[0]}; # I like to dereference early, it makes my @B = @{$_[1]}; # the rest of the code more readable. while( @A and @B ) { return 1 if &$code( pop(@A), pop(@B) ) } return 0 }; my $All = sub { my @A = @{$_[0]}; my @B = @{$_[1]}; while( @A and @B ) { return 0 unless &$code( pop(@A), pop(@B) ) } return 1 }; return ( $Any, $All ); }