The variable $^O also known as $OSNAME contains the the name of the operating system under which this copy of Perl was compiled.

$^O is the official name. You can also import the $OSNAME from the English module.

examples/osname.pl

use strict;
use warnings;
use 5.010;
use Config;
use English qw($OSNAME);

say $^O;
say $OSNAME;
say $Config{'osname'};

On MS Windows it is always MSWin32 regardless the version of Windows or if it is 32 bit or 64 bit.

On Linux it is always linux.

On Mac OSX it is always darwin.

See also the official documentation.