# $string should contain the 'slurped' file my @newfields; foreach(split(/\s*,\s*/,$string)){ s/^([A-Za-z0-9+\/]*)$/decode_base64($1)/e; push(@newfields,$_); } my $newfile = join(',',@newfields);