#!/usr/local/bin/perl -w use strict; use URI; my $url = 'http://www.example.com/foo/bar.pl?baz'; my $u1 = URI->new($url); my @seg = $u1->path_segments; print "file: $seg[-1] \n";