#!/usr/bin/perl -w
#by Torben Menke
#http://www.entorb.net
# Converts char-encoding of text-files to utf8
# Output = new directory

use strict;
use warnings;
use Data::Dumper;
use Encode;

my @listOfFiles = @ARGV;
die "Give files as parameter! (e.g. *.txt)\n" if not @listOfFiles;
print "Working on ",$#listOfFiles +1 , " Files\n";

my $outdir = 'utf8';
my $oldencoding = '';
my $newencoding = 'utf8';

print "What encoding do the files have? Enter Number:\n";
print "1\tISO-8859-1\tWindows\n";
print "2\tCP850\tDOS\n";
print "3\t???\tMac\n";
print "0\tEXIT\n";
chomp (my $input = <STDIN>);
if ($input eq '') { $input = 1 ; print $input,"\n"; } # Enter -> 1

# str -> int
$input += 0;

die "Goodbye\n" if ($input == 0 or $input >3);

if ($input == 1) {
$oldencoding = "ISO-8859-1";
}elsif ($input == 2) {
$oldencoding = "CP850";
}



mkdir $outdir unless (-d $outdir);

foreach my $filename (@listOfFiles) {
open (FILE, "< $filename") or die $!;
my @fileasarray = <FILE>;
close(FILE);

@fileasarray = map {decode($oldencoding,$_)} @fileasarray;
@fileasarray = map {encode($newencoding,$_)} @fileasarray;
if ($newencoding eq 'utf8') {
# correct EndOfLine
@fileasarray = map {s/\r\n$/\n/;$_} @fileasarray;
}


open (OUTFILE, "> $outdir/$filename") or die $!;
print OUTFILE join '' , @fileasarray;
close(OUTFILE);


}

Hope you found what you where looking for. Feel free to drop me a line
Torben