my %dispatch = ( A => \&func_a, B => \&func_b, C => \&func_c, D => \&func_d, E => \&func_e, ); for my $token (split //, $func_com) { push @all_res, [$dispatch{$token}->(@some_val)]; }