@array = qw("User1 PS1 10.10.1.1","User2 PS2 10.10.1.2","User3 PS3 20.20.1.1","User4 PS4 20.20.1.2"); ($ip[0] = $array[0]) =~ s/User1 PS1 (.+)/$1/; ($ip[1] = $array[3]) =~ s/User4 PS4 (.+)/$1/;