#!/usr/local/bin/perl use strict; use warnings; use Data::Dumper; my %commands = ( 'command1' => { 'description' => "Does something", 'function' => sub { my $var = shift; return "var = $var\n" } } ); my $cmd = 'command1'; print $commands{$cmd}{'function'}->("hello");