http://www.perlmonks.org?node_id=530108

# to call the subroutine you now do this: # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ # log_file($logfile, "I want to append this text to the file"); #This subroutine creates a time stamp.. when i print it outside the su +broutine it prints out nicely, when i put print "$file"; sub get_timestamp { my($sec,$min,$hour,$mday,$mon,$year) = localtime(time) +; if ($mon < 10) { $mon = "0$mon"; } if ($hour < 10) { $hour = "0$hour"; } if ($min < 10) { $min = "0$min"; } if ($sec < 10) { $sec = "0$sec"; } $year=$year+1900; return $year . '_' . $mon . '_' . $mday . '_' . $hour . '_' . $min . ' +_' . $sec; } my $unique_filename = '' . get_timestamp(); my $file = $unique_filename; my $logfile = '../' . FOLDER . "/$file"; #when i print logfile it gives a path.. it works fine. sub log_file{ #error says i can't open logfile or invalid use of concatenation my $logfile = shift; open (LOGFILE, ">>$logfile") or die "cannot open logfil +e for append: $!"; print LOGFILE join(" ",@_,"\n"); }