in reply to Strip first name from string

Use s/// to delete everything before the last name:
use warnings; use strict; my $contact = "Firstname Lastname"; $contact =~ s/ .* \s (\S+) $ /Mr. $1/x; print "$contact\n";

Or maybe Lingua::EN::NameParse

Replies are listed 'Best First'.
Re^2: Strip first name from string
by Skeeve (Parson) on Jan 29, 2014 at 07:35 UTC

    Your regexp is too "expensive". You do not need capturing.

    Simply delete everything up to a whitespace:

    use warnings; use strict; my $contact = "Firstname Lastname"; $contact =~ s/^.*\s/Mr. /; print "$contact\n";

    s$$([},&%#}/&/]+}%&{})*;#$&&s&&$^X.($'^"%]=\&(|?*{%
    +.+=%;.#_}\&"^"-+%*).}%:##%}={~=~:.")&e&&s""`$''`"e