my %dispatch=( A=>sub { split(/!/,$$_[0]); }, ... ); sub dispatch { my $x=$letters[random($nLetters)]; my $y='xyzzy!' x random(1000); if (exists $dispatch{$x}) { $dispatch{$x}->(\$y); } else { warn "Huh?"; } }