for ($Count=1; $Count<=4; $Count++) { if ($showrunOutput=~/encryption\skey\s$Count\s(.+)\s\n/){ print $1; } }