my %hash = (one => 1, two => 2, three => 3); my $output; open FH, '>', \$output; my $old_fh = select(FH); my $key; foreach $key (keys %hash) { write; } select ($old_fh); print $output; format FH = @<<<<<<<<< @## $key, $hash{$key} .