#!/usr/bin/perl open F, "packdrake -c @ARGV | hdlist2groups - |"; foreach (<F>) { chop; /(.*):(.*)/; $l{$2}{$1} = undef; } close F or die; foreach (sort keys %l) { print "$_\n"; print "\t$_\n" foreach sort keys %{$l{$_}}; print "\n"; }