my $input = "(55.950254, -3.187606)"; ( my $output = $input ) =~ s{([-\d.]+), # capture the first number to + $1 \s+ # at least one space ([-\d.]+) # capture the second to $2 } {$2 $1}x; # reverse $1 & $2 print $output;
See perlre and perlretut for help with regular expressions, and Regexp Quote-Like Operators in perlop for s///.
update: added references to documentation
In reply to Re: Swapping two parts of a string
by FunkyMonk
in thread Swapping two parts of a string
by Harch84
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |