Last updated on April 27th, 2022 at 01:43 pm
Just a very simple command to determine the operating system in which the script is running
#!/usr/bin/perl
print "The OS in which the script is running is:-\n";
print "$^O";
Output

Use English module
Print operating system name using english module
use English qw' -no_match_vars ';
print "$OSNAME\n";
Use Config module
You can also use config module to find the operating system name
use Config;
print "$Config{osname}\n";
Don’t have these modules installed ?
- No problem there is an easy method to install modules faster, check our tutorial on how to easily install perl modules.
Document
More details on perl variables can be found here.