in reply to pls explain following syntax

You'll have better luck if you put your code in <c>...</c> tags.

$line =~ /^([^,]*),(.*)$/ matches any string with a comma in it. It captures everything before the first comma, and everything after the first comma.

$flat_file =~ m!^.*/([^/]+)$!){ $flat_file = $1;} should be replaced with

use File::Basename qw( fileparse ); $flat_file = fileparse($flat_file);

File::Basename