#! /usr/bin/perl -l my $url = "http://example.com/user/1234/" ; $url =~ s![^/]+(?=/$)!_bla_! ; print "URL = $url" ; #### s![^/]+(?=/)$!_bla_!