use strict; use warnings; use feature 'say'; use Scope::Upper qw/ unwind :words /; sub my_grep (&@) { my $code = shift; my @out; for ( @_ ) { say "in @{[ (caller(0))[3] ]}, processing the $_"; my $result = &{ $code }; unwind @out, UP UP if $result eq 'leave'; push @out, $result } return @out; } sub maybe_working { my @out = my_grep { return /4/ ? 'leave' : $_ } 1 .. 5; say 'still here, but you won\'t see this line!'; return @out; } say "in final output: $_" for maybe_working; say 'exiting...';