#!/usr/bin/env perl use 5.010; use strict; use warnings; # a closure over a hash which takes a key as an argument and returns two subs # which return the key and its value from the hash sub get_caller { my $h = shift; return { parameter => sub { my $k = shift; my $v = $h->{$k}; return { name => sub { return $k }, val => sub { return $v } }; } }; } my $c = get_caller( {'a.x' => 1, 'b.y' => 2, 'c.x' => 3} ); print $_->{name}(), ' : ', $_->{val}(), "\n" for $c->{parameter}('a.x');