Perfect fluid spacetimes and gradient solitons