Your problem may be that the first arg to split is a regular extression -- and the vertical bar is a pattern separator with an empty extression on its left -- which can always match. If you are only wanting the one number you show, then your could use:
$data =~ /gi\|(\d+)\|ref/ and $number = $1;
Note that the vertical bar is escaped using the backslash.
--Dave