while () { my ($MMDDdata, $Stages1, $LAT1, ...) = unpack($ormat1, $_); last if (!defined($LAT2)); print OUT "$MMDDdata 0000 $LAT1 $LONG1 ...\n"; }