#!/usr/bin/perl use strict; use File::Basename; my @paths = ( 'www.google.com/folder/', 'www.google.com/folder/onething.htm', 'www.hotmail.com/folder/', 'www.hotmail.com/folder/anotherthing.htm', 'www.hotmail.com/folder' ); foreach my $path ( @paths ) { print "PATH: $path\n"; # This line does all the work. my ($base, $dir, $ext) = fileparse( $path, '\.[^.]*' ); printf "DIR: $dir\nBASE: $base\nEXT: $ext\n\n"; }