open (FH, 'blah.txt') or do_error('Unable to open file',$!);
sub do_error {
my $error = shift;
my $error2 = shift;
open(ERROR,'error.txt') or die "$!";
print ERROR "$error: $error2 [" .time . "]\n";
close ERROR;
print "$error: $error2 [" .time . "]\n";
}