perl -lanF", " -e "BEGIN{map{$_=pop @ARGV}$rx,$who}print join(',',map{$1 if /(?:[$rx] = )(.+)/}@F) if shift @F eq $who" persons.txt Person1 "Name|Age|Gender" Lydia,20,F