#!/usr/bin/perl -w use strict; $/ = qq{"\$"\t""\t""\n}; my $inputfile = 'C:\test.asc'; open A, $inputfile or die "Cannot open '$inputfile': $!"; while ( ) { my ($file) = /\n.*?"(.*?)"/ or next; open B, "> $file.csv" or warn( "Cannot open '$file': $!" ), next; print "[DEBUG] '$file': open ok\n"; chomp $_; print B $_; close B or warn( "Cannot close '$file': $!" ), next; print "[DEBUG] '$file': close ok\n"; }