in reply to Selectively renaming files

This is untested but might do the job or come close
use File::Copy; my @files=<*.dat>; foreach my $file (@files){ open FILE, "<$file" or die "Error $!"; my $fn; while(<FILE>){ last if ($fn)=$line=~/0 Name: (\w+\.\w+)/; } close FILE; move($file, $fn) if $fn and $fn ne $file; }