#!/bin/perl -w use strict; my $log= "logfile"; open( STDOUT, "| perl -p -e 'print q{[}, scalar localtime() , q{] };' >> $log" ) or die "cannot redirect output (open): $!"; print "Here he comes to save the day!\n"; # warning, if you don't have permission to write the file # then the open will succeed but the close will fail, # try it, it's quite surprising close STDOUT or die "cannot redirect output (close): $!";