use strict; use warnings; my $string="one two three four five six"; $string=~/^(\w+ ){2}(\w+) (\w+)/; print $2$3; #it prints the words correctly as you expected