foreach (split(" ",$str)) { print substr($_, -3); }