##
perl -E 'open my $infh, "<", "sample.txt"; while(<$infh>) {$i++} say $i;'
####
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);
}
}