Energetics and electronic structures of perylene confined in carbon nanotubes