in reply to Re: reading an input file
in thread reading an input file

I think you want something in there to ignore (or reset $section upon encountering) blank lines. Otherwise, the blank like after the code value will cause $code to be made empty. Of course, a non-blank, non-section line will do that also. For good error checking, you'd have to do something like this:
my ($section, $code, %passwds); while (<>) { chomp; undef $section, next unless /\S/; # next line is equivalent to duff's; just showing a # different WTDI next if ($section) = /^\[(.*?)\]$/; if ($section eq 'CODE') { warn "overriding previous CODE" if defined $code; $code = $_; # CODE section automatically ends after one line undef $section; } elsif ($section eq 'PASS') { if ((my ($name, $pass) = split) != 2) { warn "bad input $_ ignored"; next; } $passwds{$name} = $pass; } else { warn "unexpected input $_; possibly invalid section $section"; } }