sub foo { this; that; my $bar = sub { # ... }; # EDIT: this semi needs to be here if(cond) { $bar->(); } else { for (a loop) { something based on $_; $bar->(); } } }