while (my $line = <$fh>) { $line =~ /^([^ ]+) ([^ ]+)/; print "$1 $2" . "\n" if $1 && $2; }