use Errno qw( EWOULDBLOCK ); if (flock(..., ... | LOCK_NB)) { lock obtained } elsif ($! == EWOULDBLOCK) { lock denied } else { some error }