#!/usr/bin/perl use warnings; use strict; my %tools = ( 'program1' => { 'PARM1' => 1, 'PARM2' => 'n', 'PARM3' => 'y', 'PARM4' => 'n', 'PARM5' => 'y', 'PARM6' => 'n', 'PARM7' => 'y', 'PARM8' => 'n', 'PARM9' => 'y', 'PARM10' => 'n' }, 'program2' => { 'PARM1' => 1, 'PARM2' => 2, 'PARM3' => 3, 'PARM4' => 4, 'PARM5' => 5, 'PARM6' => 6, 'PARM7' => 7, 'PARM8' => 8, 'PARM9' => 9, 'PARM10' => 10 }); open (my $oh,"> $0-settings.txt") or warn "$!\n"; foreach my $tab (sort keys %tools){ print $oh "\n$tab\n"; foreach my $parm (custom_sort(\%{$tools{$tab}})) { print $oh " $parm = $tools{$tab}{$parm}\n"; } } close $oh; #for my $key ( custom_sort(\%hash) ) { # print "Key: $key\n"; #} sub custom_sort { my $hash = shift; return map { $_->[0] } sort { $a->[1] cmp $b->[1] || $a->[2] <=> $b->[2]} map { [ $_, /(\w+)(\d+)$/ ] } keys %$hash; }