my $watchlog = '/tmp/watchlog.txt'; printLog("Watch file: $watchlog\n"); #Whatever and wherever you want to print sub printLog { my $info = shift @_; open (LOG, '>>:encoding(utf8)', $watchlog) or die "Cannot open the logfile. $!\n"; print LOG $info; close LOG; } #END SUB printLog