sub split_it_this_a_way { my $string = shift || die "die, die, kill you all!"; my ( $second, $first ) = split '\.', reverse($string), 2; ( ~~reverse($first), $second ); } my $str = "x.z.y"; print $str, " -> ", join(" + ", split_it_this_a_way($str)), $/;