- #!/usr/bin/env perl -l for new lines - Using my ($name, $code, $count) = split /\Q$sep/; instead of array and hard coding separator - my @codes = sort keys %codes_found; Instead of looping through the hash - Using for instead of foreach - print join $sep => $name, map { $data{$name}{$_} || '' } @codes; This is exactly what I was looking for. Idiomatic and very readable.