while (<$fh>) { chomp; s/^\s+//; next if !length; s/\s+$//; s/\s+/ /g; ... }