#!/usr/bin/perl -w use strict; my @list = qw(1 Mike testing 2 Richard testing2 3 David Testing3); my @records; my $r; my $c = 1; foreach my $f (@list) { if ($c == 1) { $r->{id} = $f } if ($c == 2) { $r->{name} = $f } if ($c == 3) { $r->{subject} = $f; print "Pushing Id: $r->{id}\t Name: $r->{name}\t Subject: $r->{subject}\n"; # print "Anonymous hash: $r\n"; push(@records, $r); $c = 1; $r = {}; next; } $c++; } foreach (@records) { print "ID: $_->{id}\t"; print "Name: $_->{name}\t"; print "Subject: $_->{subject}\n"; }