#!/usr/bin/perl -w use strict; use warnings; use Data::Dumper; my %hash; my ($w1, $w2, $w3) = ("blue", "marbles", "lottery"); my $count = 17; my $tot_counts = 42; $hash{$w1}{$w2} = { total_counts => $tot_counts, words => { $w3 => $count } }; # Use the reference of the hash (\%hash) rather than # just the hash values (%hash). # print Dumper(\%hash); __END__ == Output == $VAR1 = { 'blue' => { 'marbles' => { 'total_counts' => 42, 'words' => { 'lottery' => 17 } } } };