Tnx Guys! the $vgs variable is of course and error and should be $memory. After adding your suggestions, I ran the script over again and got this error:
r...@user# ./script.pl Final $ should be \$ or $name at ./script.pl line 11, within string syntax error at ./script.pl line 11, near "= "^((?!total).)*$"" Execution of ./script.pl aborted due to compilation errors. It might be something with the regex, but I can't see exactly what?? Current code: #! /usr/bin/perl use warnings; use strict; # Nagios return codes $ok = 0; $warning = 1; $critical = 2; $unknown = 3; open(my $memory,"-|","free") or die "Error: $!"; # running unix command "free" $regex = "^((?!total).)*$"; while (my $line = <$memory>){ if ($line =~ m/$regex/){ chomp $line; my @array = split /\s+/, $line; if ($array[6] >= "867580"){ print "$warning\n"; }elsif ($array[6] >= "689967"){ print "$critical\n"; }else{ print "$ok\n"; } } }