in reply to from array to hash with grep

I expect there are plenty of 'use map!' replies before I finish this, but I'll throw my torch light on the subject.

$inp{$_} = 1 grep ( /\w{3}_(\w)/, @inp ) ;

This is initially syntactically wrong. You have a list and need to iterate over it somehow.

$inp{$_} = 1 for grep ( /\w{3}_(\w)/, @inp );

However grep returns the line that matched, not what you 'captured' in $1, so you will match all lines with no change.

Hence you need to use map.

$inp{$_} = 1 for map ( /\w{3}_(\w)/, @inp );

-=( Graq )=-