#!/usr/bin/perl use strict; use File::Basename; for my $pathname ( @ARGV ) { my $ostype = ( $pathname =~ /\\/ ) ? "MSDOS" : "UNIX"; fileparse_set_fstype( $ostype ); warn "\n parsing $pathname using $ostype rules\n"; my ( $name, $path, $suffix ) = fileparse( $pathname, qr{\.\w+$} ); print "Name: $name\nPath: $path\n.Ext: $suffix\n"; } #### $ ./test.pl 'c:\foo\bar\baz.exe' /usr/share/doc/bash/bash.pdf parsing c:\foo\bar\baz.exe using MSDOS rules Name: baz Path: c:\foo\bar\ .Ext: .exe parsing /usr/share/doc/bash/bash.pdf using UNIX rules Name: bash Path: /usr/share/doc/bash/ .Ext: .pdf