You shouldn't be using ioctl in perl. If your structure and C's disagree even slightly, then weird things can happen. If your structure and perl's completely agree, weird things can still happen. There may be memory alignment considerations and the like which rearrange or misalign the members from the arrangement you expected, only the C compiler's judgement should be trusted on that.
I seem to remember 'struct flock''s arrangement does seem to be different in OSX than in Linux, too. Something about one of the types involved not actually being an integer anymore.
Fortunately, perl has a built-in flock function so you don't need to call ioctl yourself. It's not even a module, it comes with standard perl.
$ perldoc -f flock
flock FILEHANDLE,OPERATION
Calls flock(2), or an emulation of it, on FILEHANDLE. Returns
true for success, false on failure. Produces a fatal error if
used on a machine that doesn't implement flock(2), fcntl(2)
locking, or lockf(3). "flock" is Perl's portable file locking
interface, although it locks only entire files, not records.
Two potentially non-obvious but traditional "flock" semantics
are that it waits indefinitely until the lock is granted, and
that its locks merely advisory. Such discretionary locks are
more flexible, but offer fewer guarantees. This means that
programs that do not also use "flock" may modify files locked
with "flock". See perlport, your port's specific documenta-
tion, or your system-specific local manpages for details. It's
best to assume traditional behavior if you're writing portable
programs. (But if you're not, you should as always feel per-
fectly free to write for your own system's idiosyncrasies
(sometimes called "features"). Slavish adherence to portabil-
ity concerns shouldn't get in the way of your getting your job
done.)
OPERATION is one of LOCK_SH, LOCK_EX, or LOCK_UN, possibly com-
bined with LOCK_NB. These constants are traditionally valued
1, 2, 8 and 4, but you can use the symbolic names if you import
them from the Fcntl module, either individually, or as a group
using the ':flock' tag. LOCK_SH requests a shared lock,
LOCK_EX requests an exclusive lock, and LOCK_UN releases a pre-
viously requested lock. If LOCK_NB is bitwise-or'ed with
LOCK_SH or LOCK_EX then "flock" will return immediately rather
than blocking waiting for the lock (check the return status to
see if you got it).
To avoid the possibility of miscoordination, Perl now flushes
FILEHANDLE before locking or unlocking it.
Note that the emulation built with lockf(3) doesn't provide
shared locks, and it requires that FILEHANDLE be open with
write intent. These are the semantics that lockf(3) imple-
ments. Most if not all systems implement lockf(3) in terms of
fcntl(2) locking, though, so the differing semantics shouldn't
bite too many people.
...