use strict; use warnings; my %UDIoutput = ( 'versionNo' => $VAR{'versionNo'}, 'sitetitle' => $VAR{'sitetitle'}, 'author' => $VAR{'PIDauthor'}, ); for my $key (%CONFIG){ $UDIoutput{$key} = $CONFIG{$key} if $key =~m/UserVar\d{2}Name/g; } use JSON; my $json_text = to_json(\%UDIoutput); print $json_text;