in reply to extracting data and saving into seperate files

Strangely enough I did something almost exactly similar a few minutes ago, but with one of my really grotty one liners.

The program you might be looking for might be this :

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

Of course, you don't want to do it like that :)

The key things to keep in mind are triggering an output destination swap when you see a filename, and triggering an output print when you see output you intend to store. Nothing else matters.

You don't need an array of files. You don't even need to hold it in memory for any operations.

If the same filename could come up more than once, use ">>" instead of ">" to open the files.