#!/usr/bin/perl -w use strict; use warnings; use Test::More qw(no_plan); use Data::Dump::Streamer; my $expected = { 'SET1' => [ [ '0','100','BOOK'], [ '1','150','PENCIL'], ], 'SET2' => [ [ '2','111','ERASER'], [ '2','200','PEN'], [ '0','220','BLACKBOARD'], [ '1','300','CHALK'], ] }; my %hoa; my $key; while ( ) { chomp; next unless /^\S/; if ( /^SET/ ) { (undef,$key) = split (/[\s:]+/,$_,2); } elsif (/^\d/) { my @rec = split(/,/,$_); push @{$hoa{$key}}, \@rec; } } print Dump(\%hoa,$expected)->Names('got','expect')->Out(); Test::More::is_deeply (\%hoa, $expected); __DATA__ SET: SET1 0,100,BOOK 1,150,PENCIL ==== SET: SET2 2,111,ERASER 2,200,PEN 0,220,BLACKBOARD 1,300,CHALK ====