Railways in Italy began under separate states before Italian unity, using private concessions to enable construction and operation.
They were based on Savoy/Piedmont, Lombardy/Venetia (under Austrian control), Tuscany, Papal states, Naples/Sicily, Sardinia.
After initial unification (c1860) the regional concessions continued until 1884, when they were reorganised into 3 main networks: Adriatic, Mediterranean and Sicilian.
These were still privately run until 1905, when the state created FS and purchased the concessions.
The north-eastern borders weren't settled until 1945, with inter-war Italian ownership of much of today's Slovenia, and Austrian ownership of Südtirol.
Slovenia's use of 3kV DC electrification (same as Italy, and unlike the rest of Yugoslavia) dates from this period.
Spain had two large private railways, the Norte and the MZA, and a number of regional networks.
RENFE was formed by the state in 1940 and absorbed all the main line railways.
The Norte had left-hand running (much of it is still extant on classic lines) while the MZA was right-hand (used also on new high speed lines).