# in while (<$fh>) {...} my ($key, $value) = split; if ( ! defined $value ) { ($value = <$fh>) =~ s/^\s*(\d+)\s*$/$1/; } # . . .