# loop through file names looking for one we can lock open ( my $file_handle, '+<', $file_name ) or next; if ( !flock( $file_handle, LOCK_EX | LOCK_NB ) ) { close( $file_handle ); next; } # do some work here based on the file contents unlink $file_name; close( $file_handle );