Mega Code Archive

 
Categories / Perl / Regular Expression
 

Swap the first two words in a string

#!/usr/bin/perl use warnings; use strict; $_ = "Berkeley: LSD and UNIX"; s/(\w+)\s+(\w+)/$2 $1/; print $_, "?\n";