my @vlan_numbers; foreach ( @snmp_strings ) { if( /\.(\d+):\w/ ) { push @vlan_numbers, $1; } } print "$_\n" foreach @vlan_numbers;