#!/usr/bin/env perl use strict; use warnings; # in my own code I would use Readonly to define these constants # -- http://search.cpan.org/~sanko/Readonly-2.05/lib/Readonly.pm my $idx_usage = 4; my $idx_mount = 5; my @input = ( '/dev/dsk/c0b0t0d0s4 12209400 5496486 6712914 46% /home', ); printf "cap = %s\n", parse_capacity(@input); exit 0; # ----- sub parse_capacity { # use $_[0] or shift @_ instead of my ($scalar) = @array; my $df_output = $_[0]; my @fields = split /\s+/, $df_output; if ($fields[$idx_mount] eq '/home') { my $use = $fields[$idx_usage]; chop $use; # remove '%' return $use; } else { return 'Match Error'; } }