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 #### insert called:0 insert called:1 first second third 1 2 1 2 3 1 2 x y z 1 2