LINE: while (defined($_ = )) { chomp $_; @F = split(/:/, $_, 0); $i ||= 1; print $i if /^n/; print $F[1] if not /^u/; print $/ if /^$/ and $i++; }