sub section($&) { my $name = shift; my $code = shift; use Benchmark; my $start = Benchmark->new(); $code->(); my $end = Benchmark->new(); print STDERR "Section $name: ", timestr(timediff($end, $start)), "\n"; } #### section A => { ... do things ... }; section B => { ...do some other stuff... } section C => { ...why not more stuff here... ...and some more!... }