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;