my @dispatch_table = ( { re => qr/^(?!START:|END:)([^*: ][^:]+):(.+)\n/, action => \&header, }, { re => qr/^START:\s*(.+)\n/, action => sub { $_[0]->{starttime} = $_[1] }, }, { re => qr/^END:\s*(.+)\n/, action => sub { $_[0]->{endtime} = $_[1] }, }, { re => qr/^(?:\* | )([^:]+):(\d+):(.+)\n/, action => sub { push @{shift->{items}}, \@_ }, }, ); #### foreach my $h (@dispatch_table) { if (my @m = $line =~ $h->{re}) { $h->{action}->($r, @m); # or $h->{action}->($r, @m, $h->{args}); next LINE; } }