use warnings; use strict; use Data::Dumper; use JSON; if (! @ARGV && ($ARGV[0] ne 'first_hash' || $ARGV[0] ne 'second_hash')){ print "need first_hash or second_hash as arg\n"; exit; } my $want = $ARGV[0]; my $file = 'data.json'; my $json; { local $/; open my $fh, '<', $file or die $!; $json = <$fh>; close $fh; } my $data = decode_json $json; print Dumper $data->{$want};