my $url = "/bla/bla/123;yarg"; # Split on ";", keep only the first chunk, then split on "/" my @tmp = split "/", (split ";", $url)[0]; # The last item holds the value we want print $tmp[-1];