use strict; use warnings; use Data::Dumper; my $code = 1; my $file_name = 'my_file_name'; my $email = 'to@address.com'; my $from = 'from@address.com'; my $from_name = 'Me'; my $subject = 'try_me'; my $body = 'Here is my message.'; my $attached = ($code) ? { attach_path => $file_name, attach_filename => $file_name, attach_type => 'application/txt', } : {} ; my %args = ( to => $email, from => $from, from_name => $from_name, subject => $subject, body => $body, %$attached ); my $success = email(%args); sub email { # Display arguments; my %arg_hash = @_; print Dumper(\%arg_hash); ... } OUTPUT: $VAR1 = { 'attach_path' => 'my_file_name', 'from' => 'from@address.com', 'subject' => 'try_me', 'from_name' => 'Me', 'attach_filename' => 'my_file_name', 'to' => 'to@address.com', 'attach_type' => 'application/txt', 'body' => 'Here is my message.' }; Unimplemented at C:\Users\Bill\perl\monks\email.pl line 38