To expand a little on what has already been said:
flock will wait, until it gets a lock. If it does not
get one, it is not likely to the next time you
try either. Your code might be useful if it was used
for open instead of flock, then,
once the open was successful, do the flock. Once.
If it's going to fail, it's going to fail here.
Also, you should only use LOCK_EX when you want to
write to the file, and then do your writing as fast
as possible, and unlock it as soon as possible. The
problem with LOCK_EX is that it not only locks your
file, but creates a bottleneck, as only one process
can access the file at a time. With LOCK_SH, many
processes can read the file simultaneously, although they
cannot write to it.
Also, you might want to write
my $file = shift;
## instead of
my $file = pop();
That way, if you ever add more parameters,
(the kind of lock perhaps?) the filename can remain the first
parameter, which reads better and fits in with general
layout of most significant to least significant
in an argument list (i.e. perl functions always have
their optional arguments at the end)