use strict; use warnings; my @inserts = ( [1, 1, 1], [2, 2, 2] ); my $outfile = 'delme.txt'; my $ins = 0; open OUTFILE, '>', $outfile; print OUTFILE <; # OP's sub sans cat calls follows