You're looking for a shared memory programming model, Perl doesn't support that. It's ruthlessly single process, save some nice child process management and an interface to
fork. If you want true SMP, you're gonna have to deal with esoteric IPC, made a bit easier with modules like
IPC::Shareable and related. You've also got file based comms, like what's described in
Parallel::ForkManager. And if you want to get fancy, take a look at
MCE - but even that just gives you a fancy file-based communication fabric. There are also interfaces to actual shared memory, shared C libraries. Another interesting idea is to use Redis, which is fundamentally a data structure middleware that provides atomic guarantees among competing processes - but it runs as a daemon and it'd have to be treated with a client/server type architecture in your program; which means you have to manage this "helper" process in the environment you're running your code. May also want to take a look at
mkfifo.