#!/usr/bin/perl use strict; use warnings; use URI; my $uri = URI->new( 'http://www.foo.com/asdf/blah/bar.html' ); print +($uri->path_segments)[-1];