#!/usr/bin/perl use strict; use warnings; use diagnostics; my %test; %test = ( array => [ { foo => 'bar', code => sub { my ($ref) = @_; 'ja' if $ref eq $test{array}[0]{foo}; }, } ], ); print "'".$test{array}[0]{code}('bar')."'\n";