#!/usr/bin/perl -w use strict; sub map2 (&@) { my $code = shift; if(@_ % 2) { require Carp; Carp::croak('Odd number of values in list'); } local ($a, $b); my @r; push @r, $code->() while ($a, $b) = splice @_, 0, 2; @r; } my %hash = qw/A B C D E F G H/; # let's remove the multiple calls to print() and # make the use of a map justifiable, shall we? print map2 sub { "key $a => value $b\n" }, %hash;