in reply to Reporting empty cells in a table of records

This works on your data:

#/usr/bin/perl -w use strict; my @idx; my @countries; open B, '< db.txt' or die $!; my $header = <B>; pos($header) = 1 + index $header, ':'; while ($header =~ /(\w+)/g) { push @idx, pos($header) - length($1); push @countries, $1; } while (<B>) { my ($fruit) = /\s([a-z]+)/; foreach (my $i = 0; $i < @idx; $i++) { print "$fruit missing for $countries[$i]\n" if length() <= $idx[$i] or substr($_, $idx[$i], length($countries[$i])) =~ /^\s+$ +/; } }

Output:

pears missing for Canada watermelons missing for US watermelons missing for Taiwan