use strict; use warnings; my $meminfo='/proc/meminfo'; my %Limits=('mem'=>0.99, 'swap'=>0.60); my %Info=(); open(MEM,"<$meminfo") or die "Can't read $meminfo: $!"; while(defined($_=)){ if(/^(Mem|Swap):\s*/){ my $which=lc($1); my ($total,$used)=split(/\s/,$'); my $pct=$total?($used/$total):0; my $test=($pct ge $Limits{$which}?"WARN":"OK"); $Info{$which}=[$used, $total, $pct, $test]; } } close(MEM); #Quick and dirty way to print the %Info hash in a readable form use Data::Dumper; print Dumper(\%Info);