my %hash = ( val1 => 1, val2 => 2, val3 => 3, ); print join ',', map {$a = "$_:$hash{$_}";$a} sort keys %hash;