#!/usr/bin/perl -w use strict; my @imgs; while (my $path = ) { chomp $path; my ($fullname, $name, $ext) = $path =~ m#(([^/]+)\.(\w+))$#; my $type = "image/$ext"; $type =~ s/jpg$/jpeg/; push @imgs, { Type => $type, ID => $name, Path => $path, Filename => $fullname, Disposition => 'attachment', }; } use Data::Dumper; print Dumper \@imgs; __DATA__ /images/logo.gif /images/footer.gif /images/whatever.gif #### $VAR1 = [ { 'ID' => 'logo', 'Disposition' => 'attachment', 'Type' => 'image/gif', 'Filename' => 'logo.gif', 'Path' => '/images/logo.gif' }, { 'ID' => 'footer', 'Disposition' => 'attachment', 'Type' => 'image/gif', 'Filename' => 'footer.gif', 'Path' => '/images/footer.gif' }, { 'ID' => 'whatever', 'Disposition' => 'attachment', 'Type' => 'image/jpeg', 'Filename' => 'whatever.jpg', 'Path' => '/images/whatever.jpg' } ];