30 Sep (Sun) | woody | pert 30 Sep (Sun) | tinny | newspaper 01 Oct (Mon) | woody | ocelot #### date | woody words | tinny words -------------+--------------------------+------------- 28 Sep (Fri) caribou litterbin 29 Sep (Sat) wasp, yowling, gorn 30 Sep (Sun) intercourse, bound, pert newspaper 01 Oct (Mon) ocelot, concubine antelope 02 Oct (Tue) vole, sausage 03 Oct (Wed) recidivist, tit #### sub make_generator { my ($day, $type, $word) = @_; return sub { my $line = ; chomp $line; return unless $line; ($$day, $$type, $$word) = split(/\s+\|\s+/, $line); return 1; }; } my $gen = make_generator(\my ($day, $type, $word)); while ($gen->()) { print "$day: encountered '$word', a $type word\n"; } __DATA__ 28 Sep (Fri) | woody | caribou 28 Sep (Fri) | tinny | litterbin 29 Sep (Sat) | woody | wasp 29 Sep (Sat) | woody | yowling 29 Sep (Sat) | woody | gorn 30 Sep (Sun) | woody | intercourse 30 Sep (Sun) | woody | bound 30 Sep (Sun) | woody | pert 30 Sep (Sun) | tinny | newspaper 01 Oct (Mon) | woody | ocelot 01 Oct (Mon) | woody | concubine 01 Oct (Mon) | tinny | antelope 02 Oct (Tue) | woody | vole 02 Oct (Tue) | woody | sausage 03 Oct (Wed) | tinny | recidivist 03 Oct (Wed) | tinny | tit