in reply to how to let sub return hash of 2 sub?

To create a code or subroutine reference, just use sub without a name:
my $x = sub { print shift };

To call such a subroutine, use the ->() dereference:

$x->('Hello world!');

It's a bit unclear what exactly you need. The following sub returns a hash of two subs:

#! /usr/bin/perl use warnings; use strict; sub two_subs { return { first => sub { return 'First: ' . shift }, second => sub { return 'Second: ' . shift }, } } print two_subs()->{first}->('A'), ' ', two_subs()->{second}->('B'), "\ +n";
لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ

Replies are listed 'Best First'.
Re^2: how to let sub return hash of 2 sub?
by Anonymous Monk on May 27, 2015 at 15:20 UTC

    ... and if OP wants to use already existing sub, use its reference ...

    ... sub two_subs { ... return { 'first' => \&ElseWhere::first , 'second' => \&ElseWhere::second } ; } # In ElseWhere ... sub first { 'first(): ' . shift } sub second { 'second(): ' . shift } ...