in reply to grep question

First, alway test the return of your open, e.g.:

open F, $cf or die "Error: $!";

Second, the string "bgs" is always true, so @CF_L will get the entire @F_cf array...maybe you wanted /bgs/? see perlre (and grep).

Third, perl grep is not the same as Unix command line grep. But I probably would use command line grep for this.

Fourth, please wrap your code in <code>...< /code> tags. It's easier to read that way.