#!/usr/bin/perl use strict; my $file='mydata.txt'; my %hash; open IN,$file || die $!; my $key; while () { ## remove the end-o-line chomp; ## blank line means a new recipe if (/^\s*$/) { undef $key; next; } ## stuff the key with something if (! defined $key) { $key=$_; next; } ## okay, split the line and add the parts push @{$hash{$key}},split /\s{2,}/,$_; } close IN; for my $key (sort keys %hash) { print "'$key' is made with: ".join(",",@{$hash{$key}})."\n"; }