use My::DBI::Table; # A Class::DBI instance my $table; # Intitilized elsewhere sub get_foos { my $foos = $table->foos(); if(wantarray) { my @array; while(my $foo = $foos->next()) { push @array, $foo; } return @array; } else { return sub { my $foo = $foos->next() or return; return $foo; }; } }