#!/usr/bin/perl -w #... (documentation could be a little better... consider using pod) use strict; use warnings; die "Usage: $0 textfile\n" unless ( @ARGV == 1 and -f $ARGV[0] ); my $txtfile = shift; open(IN, $txtfile) or die "open failed on $txtfile: $!"; my ( $LAT, $LON, $PRES, $HGHT, $TEMP, $DEWP, $DIR, $SPD ); while () { if ( /
/ ) {  # cue to grab next line for lat/lon
        $_ = ;    # use a regex to match and capture floating-pt numbers:
        ( $lat, $lon ) = ( /\s+ (-?\d+\.\d+) \s+ (-?\d+\.\d+) \s+/x;
    }
    elsif ( /^\s*(?:SFC|\d+)\s+\d+/ ) { # line of data
        my @flds = split;
        ( $PRES, $HGHT, $TEMP, $DEWP, $DIR, $SPD ) = @flds[1..4,8,9];
    }
}

open( OUT, ">", "$txtfile.reduced" ) or die "open failed on $txtfile.reduced: $!";
print OUT "$LAT, $LON, $PRES, $HGHT, $TEMP, $DEWP, $DIR, $SPD\n";
close OUT;