```{index} single: pairmap; List::Util function ``` ```{index} single: List::Util::pairmap; Perl function ``` # pairmap Run a block for each pair and concatenate the results. ## Synopsis ```perl my @out = pairmap { BLOCK } @kvlist; my $count = pairmap { BLOCK } @kvlist; # scalar context ``` For every pair the block is called in list context with `$a` set to the key and `$b` set to the value; its results are appended to the output list in order. ## What you get back In list context, the concatenation of everything every invocation of the block returned. In scalar context, the number of items that would have been returned in list context. `$a` and `$b` are aliased to the original list elements — modifications in the block are visible to the caller. ## Examples ```perl my @lines = pairmap { "The key $a has value $b" } %hash; my @flat = pairmap { ( $a, uc $b ) } %h; # values upper-cased my @pairs = pairmap { [ $a, $b ] } %h; # equivalent to `pairs` ``` ## Differences from upstream Fully compatible with upstream. ## See also - `pairgrep` — filter pairs by a predicate. - `pairfirst` — stop at the first matching pair. - `pairs` — bundle pairs into blessed arrayrefs.