$value = join ":", split " ", $value; # This is awesome $hash{$key} .= ", " if exists $hash{$key}; # I was thinking more in lines of a ternary op but this is short and concise too $hash{$key} .= $value; } print "$_ $hash{$_}\n" for sort keys %hash; # I definitely like this approach