use strict; use warnings; use File::LibMagic; use File::Spec; my $mm = File::LibMagic->new(); my $path='/home/backup/'; opendir(my $dh, $path) or die("Can't open dir $path"); while( my $file=readdir($dh) ) { my $file_path=File::Spec->join($path,$file); next unless -f $file_path; my $type=$mm->checktype_filename($file_path); $type=(split('[/;]',$type))[1]; print "$type\n"; } closedir($dh);