#!/usr/bin/env perl -l use strict; use warnings; use autodie; use constant INFO_LINES => 3; use Text::CSV; my $txt_in = 'pm_1092407_txt_in.txt'; my $csv_out = 'pm_1092407_csv_out.csv'; cat_file($txt_in, 'INPUT'); my $csv = Text::CSV::->new; open my $txt_in_fh, '<', $txt_in; open my $csv_out_fh, '>', $csv_out; my @captures; while (<$txt_in_fh>) { chomp; push @captures, $_; unless ($. % INFO_LINES) { $csv->print($csv_out_fh, [@captures]); @captures = (); } } close $txt_in_fh; close $csv_out_fh; cat_file($csv_out, 'OUTPUT'); sub cat_file { my ($file, $prompt) = @_; $prompt = 'FILE' unless defined $prompt; print '=' x 64; print "$prompt ($file):"; print '-' x 64; system cat => $file; }