while (<>) { if ($key) { m/(\d+)/ $hash{$key}=$1; $key=""; } elsif (/(\S+)\s+(\d+)/) { $hash{$1}=$2 } else { m/(\s+)/ $key=$1; } }