% cat t.pl #!/usr/bin/perl -w use strict; ... my $PIPE_STRING = q{| tail -n +2}; # starts from line 2 of input my $EMPTY_STRING = q{}; for my $chromosome ( sort { $a <=> $b } keys %chromosome_arms ) { if ( scalar @{ $chromosome_arms{$chromosome} } >= 2 ) { ... # a long running process (written in C++) my $format = qq{ask_bigdb [options] %s >> $filename\n}; # generate the command my $command = -e $filename # if file exists ? sprintf $format, $PIPE_STRING # use the tail pipe : sprintf $format, $EMPTY_STRING; # use the empty string # run the command here print $command; ... } }