my $socket_io_handlers = $mech->repl->expr('variable_that_handles_the_callbacks'); $socket_io_handlers->{on_chat} = sub { print "socket.io: Got " . Dumper \@_; };