my $info; foreach (sort keys %hoh){ my $data = "$_ "; my $tmp_hash = $hoh{$_}; foreach (sort keys %$tmp_hash){ $data .= $$tmp_hash{$_} . " "; } $info .= $data . "\n"; } print "$info"; # here you would append that to your mail body