# usage: special_last_map { block } $sentinel_variable, @list_of_values; # You should examine the value of the sentinel variable inside your code block. # It will be True for the last item in the list; False otherwise. sub special_last_map(&\$@) { my $code = shift; my $is_last_sr = shift; my $n = $#_; map { $$is_last_sr = $_ == $n; local $_ = $_[$_]; &$code } 0 .. $#_ }