#!/usr/bin/perl -w use strict; my $URK = 'http:/://blah.foo.comwhatever/dir/file.extensionelarocko?query=blah&fckj=ekjl'; my $last_slash = rindex $URK, '/'; my $last_dot = rindex $URK, '.'; my $query = rindex $URK, '?'; print "$URK\n\n"; if( ($last_slash >= 0) and ($last_dot >= 0) ) { printf "%35.35s: %s\n\n", "looks like the file name is", substr( $URK, $last_slash + 1); printf "%35.35s: %s\n\n", "and the extension is", substr($URK,$last_dot + 1); } else { print "seems like we got index.something on our hands\n\n"; } if($query >= 0) { printf "%35.35s: %s\n\n", "We even got a query string, whoa", substr($URK, $query + 1); printf "%35.35s: %s\n\n", "so the true filename would be", substr ( $URK , $last_slash + 1, $query - $last_slash ); printf "%35.35s: %s\n\n", "and the true file extension would be", substr ( $URK , $last_dot + 1, $query - $last_dot - 1 ); } __END__ =head1 RESULTS http:/://blah.foo.comwhatever/dir/file.extensionelarocko?query=blah&fckj=ekjl looks like the file name is: file.extensionelarocko?query=blah&fckj=ekjl and the extension is: extensionelarocko?query=blah&fckj=ekjl We even got a query string, whoa: query=blah&fckj=ekjl so the true filename would be: file.extensionelarocko? and the true file extension would b: extensionelarocko =cut