perl, splitting out specific parts of the string

Hi there,

I have an output from a command like this

 
# ypcat -k netgroup.byuser| grep steven
steven.* users_main,users_sysadmin,users_global,users_backup_team

and wanted to pull the 'users' netgroups returned into a perl array, that will look like this

 
users_main
users_sysadmin
users_global
users_backup_team

I would pretty happy with how to do it if everything in the string was a users_* split by a comma, but because I have the 'steven.*' with a space after it it falls over a bit,

does anyone know how I can only include the bits of the string that start with 'users_' into my array, excluding everything else? so effectively only buildng an array from the red bits below

 
# ypcat -k netgroup.byuser| grep steven
steven.* users_main,users_sysadmin,users_global,users_backup_team

any help would be greatly appreciated

Something like this:

 echo 'steven.* users_main,users_sysadmin,users_global,users_backup_team' | \
perl -ne 'print join "\n", grep { /^users/ } split /[ ,]/;'

To get only the array:

my @array = grep { /^users/ } split /[ ,]/, $line;

Thanks for that Pludi,

#!/bin/perl
use strict;
my $var = `ypcat -k netgroup.byuser| grep steven`
my @array = grep { /^users/ } split /[ ,]/, $var;

foreach (@array) {
  print "$_\n";
}

returns

# ./test.pl
users_main
users_sysadmin
users_global
users_backup_team