#!/usr/bin/perl use Text::DetectRussian; die "Usage:\n\t$0 filenames\n recodes filenames to utf8\n" unless @ARGV; foreach my $file (@ARGV){ open IN, $file or die "Can not open $file: $!\n"; undef $/; my $in=; close IN; my ($r,$e)=Text::DetectRussian::test_encoding ($in); unless ($e){ print "Nothing to do with $file;\n"; next} print "converting $file from $e to UTF8\n"; rename $file, "$file.$e"; die "Can not write on $file\n" unless open OUT, ">$file"; print OUT $_; close OUT}