#!/usr/bin/perl use strict; use warnings; use Data::Dumper; my $string = q(one tow three four five six); my @words = split(/ /, $string); my %hash1; my %hash2; $hash2{$words[1]} = join(" ", @words[2..5]); $hash1{$words[0]} = \%hash2; print Dumper(%hash1);