# Syntax sugar sub Iterator (&) { $_[0] } # Takes a sub followed by an iterator sub igrep (&$) { my ($check, $iterator) = @_; return Iterator { # While the source iterator is not exhausted while (defined( local $_ = $iterator->() )) { return $_ if $check->(); } return undef; # we are exhausted } }