Life with ‘autodie’ 

eval {
    use autodie;

    mkdir($path);
    chdir($path);
    open(my $fh, '>', $file);
};

given($@) {
    when('open') { say 'open failed'    }
    when('io:')  { say 'other IO error' }
    when('all:') { say 'other autodie'  }
    default      { say 'legacy error'   }
}