#!/usr/bin/perl -l use strict; use warnings; my $code_ref = sub { my $array_ref; my $nested_code_ref = sub { my @array = ("one","two","three"); $array_ref = \@array; }; $nested_code_ref->(); return wantarray ? ($array_ref, $nested_code_ref) : $array_ref; }; print $code_ref->()->[0]; print $code_ref->()->[1]; print( ( $code_ref->() )[1]->()[2] ); __END__ $ ./837730.pl one two three