#!/usr/bin/perl -w use strict; my %hash = (); while () { # split based on spaces my ($hex, $foo, $int) = split /\s+/; # use hash value as an array ref push @{$hash{$hex}}, $int; } #### for (keys %hash) { print "$_ = ", join(", ", sort @{$hash{$_}}), "\n"; }