Make use of warn, $SIG{__WARN__} and END {...}. If the argument to warn doesn't end with a new line ( warn $x." "; ) then the line number will be appended. In $SIG{__WARN__} do a "push(@log,"@_");". In the END block print @log.
You probably should add a $SIG{__DIE__} where you also do the "push(@log ..." before you re-raise the die. That way you'll get a log if you "die".