use strict; use warnings; use Logfile; use Communication; my $log = new Logfile (...); my $com = new Communication (...); $log->open(...); $log->write(...) if($log->is_open()); $com->do_something(); $log->write($com->get_status()) if($log->is_open()); $log->close(...);