#!/usr/bin/env perl use strict; use warnings; use Data::Dumper; my $file = 'file.txt'; open( FILE, '<', $file ) or die $!; my %hash; while ( ) { chomp; my $lines = $_; my $key = (split(/ /, $lines))[0]; my $value = (split(/ /, $lines))[1]; push @{ $hash{$key} }, $value; } print Dumper(\%hash); exit;