#!/usr/bin/perl -w use strict; use Data::Dumper; my %hash; while () { next unless /[^[:space:]]/; # make sure there's something on the line my ($key,$value) = split; $hash{$key}{$value} = 0; } foreach my $key (keys %hash) { $hash{$key} = [keys %{$hash{$key}}]; } print Dumper \%hash; __DATA__ 5 25 6 27 5 24 5 23 6 29 6 30 4 22 5 25 6 27 4 22 4 21