#!/usr/bin/perl use strict; use warnings; use Data::Dumper; # a couple of headers that vary from df to df my %name = ( percent => 'Use%', mount => 'Mounted', ); # my @headers = qw(name size used free capacity mount); my @df = `df -k`; my @headers = split /\s+/, shift @df; my %devices; for my $line (@df) { print $line; my %info; @info{@headers} = split /\s+/, $line; # note the hash slice $info{capacity} = _percentage_to_decimal($info{$name{percent}}); $devices{ $info{$name{mount}} } = \%info; } # Change 12.3% to .123 sub _percentage_to_decimal { my $percentage = shift; $percentage =~ s{%}{}; return $percentage / 100; } print Dumper \%devices;