#!/usr/bin/perl -w use strict; use warnings; use Data::Dumper; my $key; my %hoa; my @arr; while ( ) { next if (/^\s+/); if ( /^SET/ ) { my @KEY = split (/[\s:]/,$_); $key = $KEY[2]; @arr = (); # need to do this or get extra elements in second array. Try commenting this out... interesting } elsif (/^\d/) { my @INST = split(/,/,$_); push @arr, [@INST]; } $hoa{$key} = [ @arr]; } print Dumper \%hoa ; __DATA__ SET: SET1 0,100,BOOK 1,150,PENCIL ==== SET: SET2 2,110,ERASER 2,200,PEN 0,220,BLACKBOARD 1,300,CHALK ====