use strict; use warnings; my @staff = `whoare -g somegroup`; #chomping an array chomps all the elements chomp @staff; foreach my $emp (@staff) { my @fields = split /\s{2,}/, $emp; die "error! number of fields is " . scalar @fields . "! " unless ( scalar @fields == 3 ); #dispense with the opening paren to get the group ( my $def_grp = $fields[1] ) =~ s/\s*\(\s*//; #etc. }