use strict; { package Tie::Array::Apply; use overload '@{}' => sub { $_[0]->{list} }, fallback => 1; use Tie::Array; @Tie::Array::Apply::ISA = qw( Tie::StdArray ); sub TIEARRAY { my $class = shift; bless { func => shift, list => [@_], array => []}, $class; } sub FETCH { my($self,$pos) = @_; return $self->{array}->[$pos] if exists $self->{array}->[$pos]; return undef if $pos >= @{ $self->{list} }; local $_ = $self->{list}->[$pos]; return $self->{array}->[$pos] = $self->{func}->(); } } sub bind_apply(&@) { tie my @ret, 'Tie::Array::Apply', @_; return @ret; } my @bind_squares = bind_apply { $_ * $_ } 2 .. 5; print "bind_apply: ", join(', ', @bind_squares), $/; __output__ bind_apply: 4, 9, 16, 25