sub mychomp; # Needed so mychomp can be used without parens # from within mychomp sub mychomp { ref eq 'ARRAY' ? do { mychomp $_ for @$_ } : ref eq 'HASH' ? do { mychomp $_ for values %$_ } : ref eq 'REF' ? do { mychomp $$_ } : ref eq 'SCALAR' ? eval { defined && chomp $$_ } : ref || defined && chomp for @_ #### <<< :-) } # Useful stuff ends here :) # Testing stuff starts here :) $foo = "scalar\n"; @foo = (["first\n", "second\n", "third\n"], [[ "FIRST\n", "SECOND\n", "THIRD\n"], [{xyzzy => "1st\n"}],{ xyzzy => "1st\n"} ], "Just testing\n", \ $foo, \ \ \ $foo, \ [ "Testing :)\n" ], [[[[[[[[[[[[[[[[[ "DEEEEEPER!\n" ]]]]]]]]]]]]]]]]] ); mychomp @foo; use Data::Dumper; print Data::Dumper->Dump(\@foo); # oh, and $foo is chomped too, of course