chomp( my $header = <> ); my @field_names = split /\s+/, $header; my $expected_field_count = scalar(@field_names); while( <>) { chomp; my @fields = split /\s+/; my $field_count = scalar(@fields); if ($field_count > $expected_field_count)) { warn "Input error: <<<$_>>> has $field_count fields, but $expected_field_count were expected.\n", 'Fields obtained were: (', join(')(', @fields), ')'; } foreach my $index (0 .. $#fields ) { print "$field_names[$index]: $fields[$index]\n" } }