while ($fc =~ /#(\d+)\s+(\S+\s+\S+\s+)*)/g ) { $time = $1; $list = $2; @rlist = split /\n/, $list; $ofc .= "#$time\n$rlist[$#rlist]\n"; }