sub fmap(&@) { my $code = shift; return unless @_ > 1; my $x = shift; $code->( $x, $_ ) for @_; unshift @_, $code; goto \&fmap } my $n=0; fmap{ ++$n if $_[0] == $_[1] } 1,2,3,4,1,2,3; print $n; 3