あなたのアプローチを少し変えてください。検索用語とセパレーターを単一の文字列に保存する代わりに、2つの変数を使用します。
$sep = '--->';
$searchfor = '124';
$pattern = "/^$sep\s+($searchfor\d+)\s+.*/m";
// search, and store all matching occurences in $matches
if(preg_match_all($pattern, $contents, $matches)){
echo implode(' ', $matches[1])."\n";
}
出力:
12455 12477