my $waypoint = 'N43.4589 W112.9443'; my $latitude; my $longitude; foreach ( split / /, $waypoint ) { ( /^[NnSs]/ ) ? $latitude : $longitude = $_; }