use strict; use warnings; my $INV_CHAR; print "Testing for valid win32 filenames...\nThe following characters are invalid.\n"; print '\\/:*?"<>|',"\n\n"; while () { chomp; print "filename: [",$_,"] is"; print validate_it($_) ? " valid.\n" : " not valid!\n\t Filename contains \"$INV_CHAR\"\n" . "\ttry: [" . sanitize_it($_,'_') . "]\n"; } sub validate_it { local $_; $_ = shift; return /\\|\/|:|\*|\?|"|<|>|\|/ ? do { $INV_CHAR = $&; undef; } : 1; } sub sanitize_it { $_[0] =~ s/\\|\/|:|\*|\?|"|<|>|\|/$_[1]/g; return $_[0]; } __DATA__ file1 file2$is this)ok this-ok_too.. this-good.mp4 bad: b:a:d?--\ not *is*bad/ ?what?is:good this|ok|not