while (<>) { if ($str eq "") { $str = "'" . substr($line,0,$x) . "'"; } else { $str = $str . "," . "'" . substr($line,0,$x) . "'"; } }