I tried to check if XML::Simple is installed in my system or not.
perl -e \'while (<@INC>) { while (<$_/*.pm>) { print \"$_\\n\"; } }\'
>
Bravo for @user80168's solution (I'm still counting \'s !) but to avoid all the escaping involved with aliases and shells:
%~/ cat ~/bin/perlmod
perl -le'eval qq{require $ARGV[0]; }
? print ( "Found $ARGV[0] Version: ", eval "$ARGV[0]->VERSION" )
: print "Not installed" ' $1
works reasonably well.
Here might be the simplest and most "modern" approach, using Module::Runtime:
perl -MModule::Runtime=use_module -E '
say "$ARGV[0] ", use_module($ARGV[0])->VERSION' DBI
This will give a useful error if the module is not installed.
Using -MModule::Runtime requires it to be installed (it is not a core module).