my %dispatch = ( sample => sub {my $capture = shift; # do something with $capture}, good => sub {my $capture = shift; # do something with $capture}, ); while() { if (/^(sample|good)\s+(\S+)/) { $dispatch{$1}->($2); } }