#!/usr/bin/perl -w
#by Torben Menke
#http://www.entorb.net
# Multifile loop
# Use to run commands for a number of files.
# e.g. converting images using convert from imagemagick

use strict;
use warnings;



# %f = full filename (name+ext)
# %n = name without extension
# %e = extension

# @ARGV: 'instuction', files

my $instruction = shift @ARGV;
$instruction =~ s/(^'|'$)//g;

if ($#ARGV<1){
die "Too few arguments! Usage: foreach.pl 'INSTRUCTION' FILES\n where INSTRUCTION can use \n\t%f for filename (Moin.txt)\n\t%n for filename without extension (Moin)\n\t%e for extension (txt).\n";
}

#print $instruction . "\n";
my @filelist = @ARGV;

my ($f,$n,$e);
my ($out1,$out2);

format STDOUT =
@<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< @<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
$out1,$out2
.

foreach $f (@filelist){
$f = quotemeta($f);
# print "HUHU $f\n";
if ($f =~ m/^(.*)\.([^\.]+)$/){
$n = $1;
$e = $2;
}
else {
$n = $f;
$e = '';
}
$_ = $instruction;
s/%f/$f/g;
s/%n/$n/g;
s/%e/$e/g;
$out1 = $f;
$out2 = `$_`; #runs the instruction
$out2 =~ s/\n/ /g;
write;

}

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