%hash = ( # the sub { ... } means that this is a closure (a subroutine reference) command1 => sub { "command_name -n $var1 -p $var2" } ); $var1 = 'foo'; $var2 = 'bar'; # added "->()" because we are dereferencing a subroutine reference... a closure system ($hash{'command1'}->());