my @tags = qw/NAME LOCATION TIME DATE PRIORITY ATTENDEES DESCRIPTION/; my @events; open( XML, ""; # input record separator is end-tag while () # read one whole ... into $_ { my %record = (); for my $t ( @tags ) { if ( m{<$t>\s*([^<]+)} ) # capture text following an open tag { $record{$t} = $1; $record{$t} =~ s/\s+$//; # optional: remove trailing spaces } } push @events, { %record }; # @events is an array of hashes } } close XML; # to get back to the data for later use: for my $i ( 0 .. $#events ) { my $href = $events[$i]; # you get a reference to the hash my %rec_hash = %$href; # you can make a local copy of it, or print "Event #", $i+1, ":\n"; print " $_ = $$href{$_}\n" for ( keys %$href ); # just use the hash ref }