#!/usr/bin/perl use strict; my $firstrow = 1; my @positions = (); while ( defined( my $line = ) ) { if ( $firstrow ) { # process first row $firstrow = 0; my $startpos = 0; while ( ( my $nextpos = index( $line, '<', $startpos ) ) >= 0 ) { push( @positions, $nextpos ); $startpos = $nextpos + 1; } next; } # extract columns according to the calculated @positions array my @columns = (); for ( my $i = 0; $i < @positions; $i++ ) { my ( $start, $finish ) = ( $positions[$i], $positions[$i+1] ); if ( defined( $finish ) ) { push( @columns, substr( $line, $start, $finish - $start ) ); } else { push( @columns, substr( $line, $start ) ); } } print( "\"" . join( "\",\"", @columns ) . "\"\n" ); } __DATA__ ACACIA RESH CORP ACACIA TCH COM 003881307 110,725 1,875,000 SHS SHARED-OTHER 1,2,3 1,875,000 0 0 #### "ACACIA RESH CORP ","ACACIA TCH COM ","003881307 "," 110,725 "," 1,875,000"," SHS"," "," SHARED-OTHER"," 1,2,3 "," 1,875,000"," 0 "," 0"