perl -ne '/(\S+\.csv)/ and open X, ">$1" and next; next if /=/ or /^\s*$/; s/^\s+//; print X' inputfile