The first step is to check the output of the $^O variable.
If the output is for example
linux
you need more processing to detect which distribution is used.
See perldoc perlvar.
So far, you can run lsb_release -a to see which distribution is used.
If this command is not present, you can test the presence of files like:
/etc/debian_version # debian or debian based
/etc/redhat-release # rpm like distro
Other files tests examples: Detecting Underlying Linux Distro
Consider xaxes' solution too using the Linux::Distribution module to check the distribution.
If you want to detect the package manager, you can try this approach:
if ($^O eq "linux") {
my $pm;
do{
if (-x qx(type -p $_ | tr -d "\n")) {
$pm = $_;
last;
}
} for qw/apt-get aptitude yum emerge pacman urpmi zypper/;
print $pm;
}