I'm assuming that you've got the filename isolated already. If not, the File::Basename module is great. Then to get the extension, use something like this:
When you are already using File::Basename to extract the filename, then the following is also an option
($name, $path, $suffix) = fileparse('/home/foo/bar.txt', qr{[^.]*});
# or if you have a list of allowed suffices in @suf
@suf = qw/gif wav mpeg txt/;
($name, $path, $suffix) = fileparse('/home/foo/bar.txt', @suf);
# both lead to
# $name eq 'bar.'
# $path eq '/home/foo'
# $suffix eq 'txt'