#!/usr/bin/perl -w use strict; use 5.14.0; my %ahash=(one=>1, two=>2, three=>3); my $outp=[]; push @{$outp}, sprintf '"%s"=>"%s"', @$_ foreach @{&{ sub ($) { my $_=["",[]]; push @{$_->[1]},\@{$_->[0]} while @{$_->[0]=[each $_[0]]}; $_->[1] } } (\%ahash)}, @{$v}; printf "{%s}\n", join ", ", @{$outp};